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 ...
随机推荐
- DataTable通过Select进行过滤
DataTable方法测试 //测试DataTable的select DataTable dt = new DataTable(); //a.OrderType, //a.[Status] dt.Co ...
- Java反射中Class.forName和classloader的区别
Java中Class.forName和classloader都可以用来对类进行加载. Class.forName除了将类的.class文件加载到jvm中之外,还会对类进行解释,执行类中的static块 ...
- jmeter md5加密请求参数
实际的接口测试过程中,再发生http之前有可能需要对某些参数(或某几个参数的组合)进行md5加密 在jmeter中可通过两种方式来实现md5加密 beanshell实现md5加密 在org.apach ...
- 40、扩展原理-BeanDefinitionRegistryPostProcessor
40.扩展原理-BeanDefinitionRegistryPostProcessor BeanDefinitionRegistryPostProcessor extends BeanFactoryP ...
- [Luogu] 运输计划
https://www.luogu.org/problemnew/show/2680 inline 神奇的东西 最好戒掉吧(read()除外) 这道题将求解性问题转化为判定性问题,当然就是二分答案了 ...
- TensorFlow(七):tensorboard网络执行
# MNIST数据集 手写数字 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data # ...
- P2597 [ZJOI2012]灾难——拓扑,倍增,LCA
最近想学支配树,但是基础还是要打好了的: P2597 [ZJOI2012]灾难 这道题是根据食物链链接出一个有向图的关系,求一个物种的灭绝会连带几种物种的灭绝: 求得就是一个点能支配几个点: 如果一个 ...
- python 字典元素操作
#字典创建>>> dict2 = { 'abc': 123, 98.6: 37 }>>> dict2[98.6]37>>> dict2[" ...
- Myeclipse10 安装 破解 激活(含安装包,激活软件 免费)
参考博客: https://www.cnblogs.com/gzhnan/articles/9536275.html 注意 安装完成之后一定不要点 Launch Myeclipse 下载地址: htt ...
- 免sudo使用docker
前沿:通过root安装完docker,在普通用户下执行docker相关命令的时候,报权限不足: 查看sock文件的权限: [hadoop@slave1 monitor]$ ll /var/run/do ...