天天看点

Activity布局加载流程Activity布局加载流程

1.PhoneWindow.setContentView(int layoutResID)

2.PhoneWindow.installDecor()

3.PhoneWindow.generateDecor(int featureId)

4.PhoneWindow.generateLayout(DecorView decor)

5.PhoneWindow.onResourcesLoaded(LayoutInflater inflater, int layoutResource)

Activity.setContentView() 实现了把布局文件中对应的内容加载到 DecroView 中 contentParent 是一个 id 为 content 的 FrameLayout,Activity 对应的布局内容就是添加在这个 FrameLayout 中
在 Activity 的 onCreate()、onResume() 中,不能直接获取 View 的宽高,因为 View 需要 onMeasure() 之后才能获取到真实宽高,onMeasure() 在 Activity 的 onResume() 之后执行的