zoukankan      html  css  js  c++  java
  • Gui系统之View体系(2)---View的setContent

    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.

  • 相关阅读:
    如何让ListView的item不可点击
    [Android] ListView中如何让onClick和onItemClick事件共存
    [Android] RelativeLayout, LinearLayout,FrameLayout
    [Android]drawable-nodpi文件夹 的作用
    [转]安装和使用JD-Eclipse插件
    jmeter下载及安装配置
    MySql安装后在服务管理器里边找不到MySql服务项的解决办法
    两步破解IntelliJ IDEA 教程(无敌版)
    进程和线程区别和联系
    webservice--cxf和spring结合,发布restFull风格的服务
  • 原文地址:https://www.cnblogs.com/deman/p/5877924.html
Copyright © 2011-2022 走看看