View的绘制流程分析之三 -- layout

本文详细探讨了Android中View的layout过程,从ViewRootImpl的performTraversals()开始,经过performMeasure(),到View的layout()方法,进一步进入onLayout()函数。虽然在View基类中onLayout()为空实现,但在ViewGroup中变为抽象方法,每个ViewGroup子类需要根据自身需求实现。以FrameLayout为例,文章阐述了如何通过child.layout()为子视图设置位置,若子视图是ViewGroup则递归执行相同过程。
摘要由CSDN通过智能技术生成

转载请注明出处:http://blog.csdn.net/crazy1235/article/details/72633389


layout - 布局

确定View的最终宽高以及四个顶点的位置!

接着上一篇 View的绘制流程分析之二 – measure 往下分析layout过程!

在ViewRootImpl 中的performTraversals() 函数内部,执行performMeasure() 完毕之后,

// Ask host how big it wants to be
performMeasure(childWidthMeasureSpec, childHeightMeasureSpec);
// ...

layoutRequested = true;
final boolean didLayout = layoutRequested && (!mStopped || mReportNextDraw);
        boolean triggerGlobalLayoutListener = didLayout
                || mAttachInfo.mRecomputeGlobalAttributes;
        if (didLayout) {
            performLayout(lp, mWidth, mHeight); // 开始布局过程!

            // ...
        }
private void performLayout(WindowManager.LayoutParams lp, int desiredWindowWidth,
            int desiredWindowHeight) {
        // ... 
        final View host = mView;
        try {
            host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight());
            // ... 
            }
        } finally {
        }
    }

host就是那个DecorView对象!

然后又走到了View中的 layout()方法!

public void layout(int l, int t, int r, int b) {
        // ...

        boolean changed = isLayoutModeOptical(mParent) ?
                setOpticalFrame(l, t, r, b) : setFrame(l, t, r, b);

        if (chan
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值