Activity绘制流程

onCreate

1. ApplicationThread#schedueLaunchActivity
2. ActivityThread#handleLaunchActivity
3. ActivityThread#performLaunchActivity
4. Activity#attach

调用Activity.setContentView

1. PhoneWindow#installDecor(初始化DecorView及ContentParent)
2. mLayoutInflater.inflate(layoutResID, mContentParent);
#inflate此处
LayoutInflator#rInflate 最终finishInflate=true:触发parent.onFinishInflate();
LayoutInflator#createView#constructor.newInstance(args);最终调用 XXX(Context context, AttrsSet args);
# 至此,View对象们已经存在mContentParent的子对象中.

onResume

  1. ActivityThread#performResumeActivity
  2. Activity#performResume

2.1 performResume#performRestart
2.2 触发performStart,调试模式弹窗,-> enterReady
2.2.1 activity.getWindow().getDecorView().setVisibility(View.VISIBLE);
2.2.2 triggerViewsReady#decor.invalidate();
2.2.3 View#invalidateInternal内

            // Propagate the damage rectangle to the parent view.
            final AttachInfo ai = mAttachInfo;
            final ViewParent p = mParent;
            if (p != null && ai != null && l < r && t < b) {
                final Rect damage = ai.mTmpInvalRect;
                damage.set(l, t, r, b);
                # All or part of a child is dirty and needs to be redrawn.
                p.invalidateChild(this, damage);
            }
            ViewRootImpl#scheduleTraversals#最终会重绘界面 onMeasure/onLayout/onDraw

2.3 onResume

DecorView extends FrameLayout

  • 根布局
  • mContentParent

ViewRootImpl

  • 实现View和WindowManager之间的协议。具体详看WindowManagerGlobal

WindowManagerGlobal

  • 维护View ViewRootImpl LayoutParams的顺序存储。

updateViewLayout和removeView都是在ViewRootImpl的基础上进行操作的
view.invalidate最终也是调用到ViewRootImpl#scheduleTraversals,其performMeasure/Layout/Draw

ViewRootImpl的内部缓存View对象

WindowManager的实现类WindowManagerImpl的内部调用WindowManagerGlobal的具体实现。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容