日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

Gui系统之View体系(2)---View的setContent

發(fā)布時(shí)間:2025/4/14 windows 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Gui系统之View体系(2)---View的setContent 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.從SetContentView講起

1.1Activty的setContentView里面的內(nèi)容

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

首先這個(gè)getWindow是什么?

mWindow, 作用:

mWindow = new PhoneWindow(this);

在attach@ativity 方法里面定義的。默認(rèn)就是PhoneWindow.也就是Activity里面包含的window實(shí)例。

@Overridepublic 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.

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

1.2 installDecor

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

第二創(chuàng)建mContentParent。

mContentParent= generateLayout(mDecor);

我們來看看generateLayout。

有一堆的判斷,但是最終 加入Decor的過程,其實(shí)就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來管理的。

一個(gè)Activity中對(duì)象持有mWindow對(duì)象。

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

轉(zhuǎn)載于:https://www.cnblogs.com/deman/p/5877924.html

總結(jié)

以上是生活随笔為你收集整理的Gui系统之View体系(2)---View的setContent的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。