View System of Gui system (2) --- setContent of View, --- viewsetcontent
1. Start with SetContentView
Content in setContentView of 1.1Activty
public void setContentView(@LayoutRes int layoutResID) { getWindow().setContentView(layoutResID); initWindowDecorActionBar(); }
First, what is getWindow?
MWindow, function:
mWindow = new PhoneWindow(this);
Defined in the attach @ ativity method. The default value is PhoneWindow, which is the window instance contained in the Activity.
@ Override public void setContentView (int layoutResID) {// Note: FEATURE_CONTENT_TRANSITIONS may be set in the process of installing the window // decor, when theme attributes and the like are crystalized. do not check the feature // before this happens. if (mContentParent = null) {installDecor ();} else if (! HasFeature (FEATURE_CONTENT_TRANSITIONS) {mContentParent. removeAllViews ();} if (hasFeature (FEATURE_CONTENT_TRANSITIONS) {final Scene newScene = Scene. getSceneForLayout (mContentParent, layoutResID, getContext (); transitionTo (newScene);} else {mLayoutInflater. inflate (layoutResID, mContentParent);} mContentParent. requestApplyInsets (); final Callback cb = getCallback (); if (cb! = Null &&! IsDestroyed () {cb. onContentChanged ();}}SetContentView
What is mContentParent? You can see the definition:
// This is the view in which the window contents are placed. It is either // mDecor itself, or a child of mDecor where the contents go.
Note-based awareness means that mContentParent is the parent layout we add to layout. It has two possibilities: DecorView or its sub-View.
1.2 installDecor
InstallDecor has two parts. First, new Decor, if needed.
Create mContentParent.
MContentParent = generateLayout (mDecor );
Let's take a look at generateLayout.
There are a bunch of judgments, but the process of adding Decor is actually two sentences.
View in = mLayoutInflater. inflate (layoutResource, null );
Decor. addView (in, new ViewGroup. LayoutParams (MATCH_PARENT, MATCH_PARENT ));
The first sentence is to convert the layout id into a View. The second sentence is to add the View to Decor.
1.3 add Decor to Activity.
View in Activity is managed by Window and WMS.
Objects in an Activity hold mWindow objects.
MWindow-> WindowManager-> WindowManagerImpl-> WMS-> ViewRoot-> add View.