View System of Gui system (2) --- setContent of View, --- viewsetcontent

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.