xml加载流程
继承Activity的流程
1.Activity
2.Dialog
3.PopupWindow
4.Toast
ActivityThread.performLaunchActivity
-->activity.attach
--> new PhoneWindow()
-->mInstrumentation.callActivityOnCreate
--》getWindow().setContentView(layoutResID); PhoneWindow.setContentView --- 主要目的 创建 DecorView拿到Content
--》 installDecor();
--》 mDecor = generateDecor(-1);
--》 new DecorView()
--》setWindow(PhoneWindow);
--》 mContentParent = generateLayout(mDecor);
--》getLocalFeatures
--》 R.layout.screen_simple DecorView下的LinearLayout
--》 mDecor.onResourcesLoaded(mLayoutInflater, layoutResource); 把R.layout.screen_simple添加到 DecorView(FrameLayout)
--》inflater.inflate(layoutResource, null);
--》 addView(layoutResource , 0, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
--》 ViewGroup contentParent = (ViewGroup)findViewById(ID_ANDROID_CONTENT); contentParent 就是R.layout.screen_simple 里的FrameLayout @android:id/content
--》 mLayoutInflater.inflate(layoutResID, mContentParent);
AppCompatDelegate.setContentView
-->getDelegate()
-->AppCompatDelegateImpl.onCreate
--》ensureWindow(); AppCompat install itself into the Window
--> ensureSubDecor();
--> mSubDecor = createSubDecor();
--> ensureWindow();
--> mWindow.getDecorView();
--> installDecor();
-->
--> subDecor = (ViewGroup) inflater.inflate(R.layout.abc_screen_simple, null);
--> final ViewGroup windowContentView = (ViewGroup) mWindow.findViewById(android.R.id.content);
-->while (windowContentView.getChildCount() > 0)
--> windowContentView.setId(View.NO_ID);
--> contentView.setId(android.R.id.content);
--> mWindow.setContentView(subDecor); /
--》mContentParent.addView(view, params); mContentParent就是R.layout.activity_main
--> ViewGroup contentParent = mSubDecor.findViewById(android.R.id.content);
--> LayoutInflater.from(mContext).inflate(resId, contentParent);