快速了解Android onMeasure() onLayout()
来源:互联网 发布:mac 批量保存网页图片 编辑:程序博客网 时间:2024/04/27 06:29
通过继承ViewGroup时一般都要重写onMeasure() onLayout()方法
@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {//获取模式和大小,边界参数共有3种模式:UNSPECIFIED一般为0, EXACTLY准确尺寸, AT_MOST自适应尺寸 int w_mode = MeasureSpec.getMode(widthMeasureSpec);int w_size = MeasureSpec.getSize(widthMeasureSpec);int h_mode = MeasureSpec.getMode(heightMeasureSpec);int h_size = MeasureSpec.getSize(heightMeasureSpec);//计算自定义的所有子控件的大小 measureChildren(widthMeasureSpec, heightMeasureSpec);//通知父控件,宽高需要多大地方放置子控件//setMeasuredDimension(resolveSize(size, widthMeasureSpec),resolveSize(size, heightMeasureSpec));setMeasuredDimension(w_size, h_size);Log.e("onMeasure","宽mode=" + w_mode + "宽size="+ w_size+ "高mode=" + h_mode+ "高size=" +h_size);// super.onMeasure(widthMeasureSpec,heightMeasureSpec);}//onLayout是为了指定视图的显示位置,方法执行的前后顺序是在onMeasure之后,因为视图肯定是只有知道大小才能指定位置放置
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { // 记录总高度 int mTotalHeight = 0; // 遍历所有子视图 int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View childView = getChildAt(i); // 获取在onMeasure中计算的视图尺寸 int measureHeight = childView.getMeasuredHeight(); int measuredWidth = childView.getMeasuredWidth(); childView.layout(l, mTotalHeight, measuredWidth, mTotalHeight + measureHeight); mTotalHeight += measureHeight; } }
1 0
- 快速了解Android onMeasure() onLayout()
- Android onMeasure and onLayout
- Android中的OnMeasure及OnLayout
- Android API之onLayout, onMeasure
- Android中的OnMeasure及OnLayout
- Android onmeasure 与 onLayout示例
- onLayout onMeasure
- Android 理解 onMeasure onLayout的过程
- Android自定义控件的onMeasure和onLayout
- android 中的onlayout onmeasure调用顺序
- Android measure、onMeasure、layout、onLayout关系作用
- Android onMeasure,onLayout,onDraw的理解
- Android自定义控件onMeasure、onLayout介绍
- Android 自定义View基础 onMeasure & onLayout
- onMeasure和onLayout
- onMeasure和onLayout理解
- onMeasure和onLayout
- onMeasure和onLayout理解
- 【网络赚钱】这是一款神奇的软件-安装无需注册就能赚钱-提现秒到账
- excel数据导入到mysql的问题
- “贩卖儿童者,一律死刑!”可乎?
- 快速简单理解i2c标准协议
- Linux系统新手学习的11点建议
- 快速了解Android onMeasure() onLayout()
- eSDK UC极简开发敏捷创新系列之三: Huawei eSDK UC玩法进阶
- BZOJ 3504 [Cqoi2014] 危桥 最大流
- Bootstrap中的弹出框插件popover.js中的参数title、content不能使用html代码
- 北大OJ_1002题:487-3279
- C++基础概念
- 浙江大学PAT_甲级_1046. Shortest Distance (20)
- 讲讲Android开发超常见的内存泄露以及解决
- 解决AD 不能打开DDB文件的解决方案