FrameLayout 测量过程(代码流水线)

   /**
     * {@inheritDoc}
     * 如果,子 view如果设置属性是 match_parent,
     * 如果,measureMatchParentChildren是true (其实就是framlayout模式是非精准模式)
     * 那么这种子view是被测量了两次
     */
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int count = getChildCount();

        //当FrameLayout的宽和高 只有同时设置为 match_parent
        //当FrameLayout的宽和高 指定的size
        ///measureMatchParentChlidren = false,否则为true。

        //MeasureSpec.EXACTLY时,就表示当前视图的大小等于参数measureSpec中所指定的值。

        //当FrameLayout 非精准模式,这时候要把所有宽高设置为 //match_parent的子View都记录下来
        // 这时候FrameLayout的宽高同时受子View的影响
        final boolean measureMatchParentChildren = MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY || MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY;

        mMatchParentChildren.clear();

        int maxHeight = 0;
        int maxWidth = 0;
        int childState = 0;//宽高的期望类型

        //测量孩子同时,计算出一个最大宽高
        for (int i = 0; i < count; i++) {
            final View child = getChildAt(i);
            if (mMeasureAllChildren || child.getVisibility() != GONE) { //一次遍历每一个不为GONE的子view

                //第一次测量孩子
                measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);

                final LayoutParams lp = (LayoutParams) child.getLayoutParams();

                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());

                //的mMatchParentChlidren的list里存的是设置为match_parent的子view。
                if (measureMatchParentChildren) {
                    if (lp.width == LayoutParams.MATCH_PARENT || lp.height == LayoutParams.MATCH_PARENT) {
                        mMatchParentChildren.add(child);
                    }
            
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值