Gui系統之View體系(2)---View的setContent,---viewsetcontent

來源:互聯網
上載者:User

Gui系統之View體系(2)---View的setContent,---viewsetcontent

1.從SetContentView講起

1.1Activty的setContentView裡面的內容

    public void setContentView(@LayoutRes int layoutResID) {        getWindow().setContentView(layoutResID);        initWindowDecorActionBar();    }

首先這個getWindow是什嗎?

mWindow, 作用:

mWindow = new PhoneWindow(this);

在attach@ativity 方法裡面定義的。預設就是PhoneWindow.也就是Activity裡麵包含的window執行個體。

@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

mContentParent 是什麼,可以看定義:

// 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.

按注釋的意識就是mContentParent 就是我們加入layout的父布局,它有2種可能,DecorView 或者它的子View。

1.2 installDecor

installDecor就2塊 ,第一,new Decor,如果需要的話。

第二建立mContentParent。

mContentParent= generateLayout(mDecor);

我們來看看generateLayout。

有一堆的判斷,但是最終 加入Decor的過程,其實就2句。

View in = mLayoutInflater.inflate(layoutResource, null);
decor.addView(in, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));

第一句就是把layout id 變換成View。第二句就是把View加入到Decor中。

1.3 把Decor加入到Activity中。

Activity中的view,是通過Window 然後跟WMS來管理的。

一個Activity中對象持有mWindow對象。

mWindow ->WindowManager->WindowManagerImpl->WMS->ViewRoot->add View.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.