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

被折叠的 条评论
为什么被折叠?



