Android ViewRootImpl Choreographer SurfaceFlinger 学习笔记

本文详细探讨了Android中ViewRootImpl、Choreographer以及SurfaceFlinger的关键作用。首先,说明了DecorView与ViewRootImpl的关系,以及如何通过requestFitSystemWindows在ViewRootImpl中实现系统窗口适配。接着,分析了requestLayout在View和ViewRootImpl中的实现过程,揭示了布局更新的机制。最后,虽未直接涉及Choreographer,但其在UI帧同步中的重要性不言而喻,为Android流畅动画提供了基础。

一,每个DecorView对应一个ViewRootImpl,并且DecorView的mParent是ViewRootImpl。

二,View中requestFitSystemWindows的实现就是依赖于ViewRootImpl中的requestFitSystemWindows。可以参考http://blog.youkuaiyun.com/kobe_gong_5/article/details/45999713

In View.java

    public void requestFitSystemWindows() {
        if (mParent != null) {
            mParent.requestFitSystemWindows();
        }
    }


In ViewRootImpl.java

    @Override
    public void requestFitSystemWindows() { // 一直追溯到这里,调用scheduleTraversals才能完成relayout的具体操作
        checkThread();
        mApplyInsetsRequested = true;
        scheduleTraversals();
    }

三,View中requestLayout的实现也是依赖于ViewRootImpl中的requestLayout。

In View.java

    public void requestLayout() {
        if (mMeasureCache != null) mMeasureCache.clear();


        if (mAttachInfo != null && mAttachInfo.mViewRequestingLayout == null) {
            // Only trigger request-during-layout logic if this is the view requesting it,
            // not the views in its parent hierarchy
            ViewRootImpl viewRoot = getViewRootImpl();
            if (viewRoot != null && viewRoot.isInLayout()) {
                if (!viewRoot.requestLayoutDuringLayout(this)) {
                    return;
                }
            }
            mAttachInfo.mViewRequestingLayout = this;
        }


        mPrivateFlags |= PFLAG_FORCE_LAYOUT;
        mPrivateFlags |= PFLAG_INVALIDATED;


        if (mParent != null && !mParent.isLayoutRequested()) {
            mParent.requestLayout();
        }
        if (mAttachInfo != null && mAttachInfo.mViewRequestingLayout == this) {
            mAttachInfo.mViewRequestingLayout = null;
        }
    }


In ViewRootImpl.java

    @Override
    public void requestLayout() {
        if (!mHandlingLayoutInLayoutRequest) {
            checkThread(); // 必须在ui线程中调用
            mLayoutRequested = true;
            scheduleTraversals();
        }
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值