MeasureSpec常用方法
package com.loaderman.customviewdemo; import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup; public class MyLinLayout extends ViewGroup {
public MyLinLayout(Context context) {
super(context);
} public MyLinLayout(Context context, AttributeSet attrs) {
super(context, attrs);
} public MyLinLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
} @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int measureWidth = MeasureSpec.getSize(widthMeasureSpec);//获取数值
int measureHeight = MeasureSpec.getSize(heightMeasureSpec);//获取数值
int measureWidthMode = MeasureSpec.getMode(widthMeasureSpec);//获取模式
int measureHeightMode = MeasureSpec.getMode(heightMeasureSpec);//获取模式 int height = 0;
int width = 0;
int count = getChildCount();
for (int i=0;i<count;i++) { View child = getChildAt(i);
measureChild(child, widthMeasureSpec, heightMeasureSpec);
int childHeight = child.getMeasuredHeight();
int childWidth = child.getMeasuredWidth(); height += childHeight;
width = Math.max(childWidth, width);
}
//设置 MeasureSpec.EXACTLY完全 MeasureSpec.UNSPECIFIED 不确定 MeasureSpec.AT_MOST 至多
setMeasuredDimension((measureWidthMode == MeasureSpec.AT_MOST) ? measureWidth
: width, (measureHeightMode == MeasureSpec.EXACTLY) ? measureHeight
: height);
} @Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int top = 0;
int count = getChildCount();
for (int i=0;i<count;i++) { View child = getChildAt(i); int childHeight = child.getMeasuredHeight();
int childWidth = child.getMeasuredWidth(); child.layout(0, top, childWidth, top + childHeight);//重新布局控件
top += childHeight;
}
}
}
MeasureSpec常用方法的更多相关文章
- 【Android 应用开发】 自定义 圆形进度条 组件
转载著名出处 : http://blog.csdn.net/shulianghan/article/details/40351487 代码下载 : -- CSDN 下载地址 : http://down ...
- 前端开发:Javascript中的数组,常用方法解析
前端开发:Javascript中的数组,常用方法解析 前言 Array是Javascript构成的一个重要的部分,它可以用来存储字符串.对象.函数.Number,它是非常强大的.因此深入了解Array ...
- Jquery元素选取、常用方法
一:常用的选择器:(李昌辉) 基本选择器 $("#myDiv") //匹配唯一的具有此id值的元素 $("div") //匹配指定名称的所有元素 $(" ...
- python浅谈正则的常用方法
python浅谈正则的常用方法覆盖范围70%以上 上一次很多朋友写文字屏蔽说到要用正则表达,其实不是我不想用(我正则用得不是很多,看过我之前爬虫的都知道,我直接用BeautifulSoup的网页标签去 ...
- C# Webbrowser 常用方法及多线程调用
设置控件的值 /// <summary> /// 根据ID,NAME双重判断并设置值 /// </summary> /// <param name="tagNa ...
- list,tuple,dict,set常用方法
Python中list,tuple,dict,set常用方法 collections模块提供的其它有用扩展类型 from collections import Counter from collect ...
- 记录yii2-imagine几个常用方法
记录yii2-imagine几个常用方法: //压缩 Image::thumbnail('@webroot/img/test-image.jpg', 120, 120)->save(Yii::g ...
- DOM常用方法总结
DOM(Document Object Model:文档对象模型)为javascript中的一部分,它为访问和修改html文档或xml文档提供了一些编程接口,DOM以对象的形式来描述文档中的内容,以树 ...
- JSP内置对象及常用方法
jsp九大内置对象及四个作用域: 何为作用域 先让我们看看效果: 大概流程是这样的,我们访问index.jsp的时候,分别对pageContext, request, session,applicat ...
随机推荐
- linux防火墙(一)
安全技术 入侵检测与管理系统IDS(Intrusion Detection Systems):特点是不阻断任何网络访问,量化.定位来自内外网络的威胁情况,主要以提供报告和事后监督为主,提供有针对性的指 ...
- 使用Dell iDRAC服务器远程控制安装操作系统简要图解
使用Dell iDRAC服务器远程控制安装操作系统简要图解 iDARC tools iDRAC又称为Integrated Dell Remote Access Controller,也就是集成戴尔 ...
- Notepad++ 连接远程 NppFTP
远程连接 1.自动安装: 插件——> Plugin Manager——>ShowPlugin Manager——>勾选NppFTP插件——>Install 2. 手动安装 ...
- 7月新的开始 - Axure学习06 - 母版的使用
母版的使用 主导航.底部.在很多页面上都是一样的: 如果在每一个页面都写一次的化.话.是非常浪费时间的,为了方便.可以使用母版: 母版可以帮助我们将一些元素重复利用,既可以保证页面的统一性.还可以节省 ...
- LightOJ - 1148-Mad Counting (数学)
链接: https://vjudge.net/problem/LightOJ-1148 题意: Mob was hijacked by the mayor of the Town "Trut ...
- myeclipse2018大括号之前会自动加空格
- Laravel 项目架构 弹性、可维护性
公司项目可能需要对架构进行重建,老大给了我一个视频让我学习里面的思想,看完后觉得收获很大,主讲人对laravel项目各个层次有很清晰的理解,力求做到职责单一分明,提高可维护性.下面是我看完视频对其内容 ...
- [Luogu] 仓鼠找sugar
https://www.luogu.org/problemnew/show/3398 树剖练习题,两个懒标记,搜索时序为全局懒标记 #include <bits/stdc++.h> usi ...
- tmux-cheatsheet
http://tmuxcheatsheet.com/ http://louiszhai.github.io/2017/09/30/tmux/ 滚屏 开启 Ctrl-b pageup/pagedown ...
- VM 虚拟机 CentOS 7 设置 桥接网络
桥接网络的设置: 安装时设置网络为桥接网络! 找到 ip 地址,设置如下 注意ip地址并不是一样的,用以区分 然后在关闭 windows 防火墙,打开 cmd 使用 ping 命令 O ...