Sogrey / Android_QA

https://sogrey.github.io/Android_QA/
MIT License
0 stars 0 forks source link

ViewRootImpl 和 DecorView 的关系是什么? #160

Open Sogrey opened 3 years ago

Sogrey commented 3 years ago
// ViewRootImpl.setView
public void setView(View view, WindowManager.LayoutParams attrs, View panelParentView) {
  requestLayout();
  // ...
  // 这里的 view 是 DecorView
  view.assignParent(this);
}

接着上面的代码看,在 ViewRootImpl.setView 里,通过 DecorView.assignParentViewRootImpl 设置为 DecorViewparent

所以 ViewRootImplDecorView 的关系就是 ViewRootImplDecorViewparent

因为 DecorView 是我们布局的顶层,现在我们就知道层层调用requestLayout 等方法是怎么调用到 ViewRootImpl 里的了。