天天看點

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() 之後執行的