一、View 通过 ViewRootImpl 来绘制
ViewRootImpl 是一个视图层次结构的顶部,在上一篇文章中我们知道了 ViewRootImpl 实现了 View 与 WindowManager 之间所需要的协议,作为 WindowManagerGlobal 中大部分的内部实现。这个好理解,在 WindowManagerGlobal 中实现方法中,都可以见到 ViewRootImpl,也就说 WindowManagerGlobal 方法最后还是调用到了 ViewRootImpl。addView,removeView,update 的调用顺序:WindowManagerImpl -> WindowManagerGlobal -> ViewRootImpl
我们看下前面调用到了 viewRootImpl 的 setView 方法:
public void setView(View view, WindowManager.LayoutParams attrs, View panelParentView) {
...
// Schedule the first layout -before- adding to the window
// manager, to make sure we do the relayout before receiving
// any other events from the s
ViewRootImpl在Android中起到关键作用,作为View与WindowManager的桥梁,负责View的绘制。当添加View时,ViewRootImpl的setView方法被调用,通过requestLayout()启动布局过程。performTraversals()方法执行测量、布局和绘制三个步骤来完成View的显示。同时,ViewRootImpl还负责事件分发,包括点击事件。当点击事件发生时,InputEvent通过一系列InputStage处理,最终由Activity的dispatchTouchEvent方法处理。整个过程中,ViewRootImpl确保了UI操作在主线程中执行,保证了界面更新的安全性。
订阅专栏 解锁全文
704

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



