FrameLayout的测量
来源:互联网 发布:富途网络怎么样 编辑:程序博客网 时间:2024/04/29 11:33
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int count = getChildCount(); //如果传入的测量规格有一个不是match_parent,则将其标为true(这里为了处理当一个父控件,比如FrameLayout布局参数设置为wrap_content,而其子view有的设置为match_parent的时候出现的矛盾) final boolean measureMatchParentChildren = MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY || MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY; mMatchParentChildren.clear(); int maxHeight = 0; int maxWidth = 0; int childState = 0; //这里遍历子view依次进行测量 for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (mMeasureAllChildren || child.getVisibility() != GONE) { //这里进行子view的测量,注意参数usedWidth与usedHeight参数都为0 ,与LinearLayout和RelativeLayout不同(不需要考虑已经被其它孩子占用的空间) measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); //child测量完成 final LayoutParams lp = (LayoutParams) child.getLayoutParams(); //记录宽子view高最大值(等子view测量完成会作为自己宽高的重要参考) maxWidth = Math.max(maxWidth, child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin); maxHeight = Math.max(maxHeight, child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin); childState = combineMeasuredStates(childState, child.getMeasuredState()); if (measureMatchParentChildren) { //记录下宽高是match_parent的子view,后面还要重新测量 if (lp.width == LayoutParams.MATCH_PARENT || lp.height == LayoutParams.MATCH_PARENT) { mMatchParentChildren.add(child); } } } } // Account for padding too maxWidth += getPaddingLeftWithForeground() + getPaddingRightWithForeground(); maxHeight += getPaddingTopWithForeground() + getPaddingBottomWithForeground(); // Check against our minimum height and width maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight()); maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth()); // Check against our foreground's minimum height and width final Drawable drawable = getForeground(); if (drawable != null) { maxHeight = Math.max(maxHeight, drawable.getMinimumHeight()); maxWidth = Math.max(maxWidth, drawable.getMinimumWidth()); } //设置自己的宽高 setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), resolveSizeAndState(maxHeight, heightMeasureSpec, childState << MEASURED_HEIGHT_STATE_SHIFT)); count = mMatchParentChildren.size(); if (count > 1) { for (int i = 0; i < count; i++) { final View child = mMatchParentChildren.get(i); final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); int childWidthMeasureSpec; int childHeightMeasureSpec; if (lp.width == LayoutParams.MATCH_PARENT) { childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth() - getPaddingLeftWithForeground() - getPaddingRightWithForeground() - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY); } else { childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, getPaddingLeftWithForeground() + getPaddingRightWithForeground() + lp.leftMargin + lp.rightMargin, lp.width); } if (lp.height == LayoutParams.MATCH_PARENT) { childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight() - getPaddingTopWithForeground() - getPaddingBottomWithForeground() - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY); } else { childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, getPaddingTopWithForeground() + getPaddingBottomWithForeground() + lp.topMargin + lp.bottomMargin, lp.height); } child.measure(childWidthMeasureSpec, childHeightMeasureSpec); } } }
0 0
- FrameLayout的测量
- FrameLayout 测量过程(代码流水线)
- 【FrameLayout】使用FrameLayout应该注意的地方
- framelayout的使用
- 复杂的FrameLayout
- FrameLayout的使用
- RelativeLayout, Framelayout的理解
- 关于FrameLayout的理解
- Framelayout的覆盖顺序
- FrameLayout的简单运用
- FrameLayout的使用进阶
- FrameLayout 的使用方法
- FrameLayout 的作用
- FrameLayout的子类ViewAnimator
- FrameLayout
- FrameLayout
- FrameLayout
- FrameLayout
- 10.12做题——NOI题库(1.13.T30)1的个数
- 【Foundation-10-5】#import <Foundation/NSArray.h>可变数组,操作
- Andrew机器学习课程笔记(6)[End]—— 机器学习的一个应用实例
- 大端序与小端序
- struts2 DMI用感叹号动态调用方法时提示there is no action mapped for
- FrameLayout的测量
- ios:多线程
- android亮度brightness
- mysql游标循环多一次的解决办法
- Eclipse中使用SVN
- C# MySQL链接数据库
- Java——2家族的金字塔
- 堆栈—冲刺十三模拟赛 外星密码
- List,Set,Map用法以及区别