zoukankan      html  css  js  c++  java
  • setContentView

    原理

    Activity中的setContentView实际上是执行phoneWindow中的setContentView,将该布局文件,解析成view,作为DecorView的子view

    源码

    Activity

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

    PhoneWindiw

    @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();
            }
            mContentParentExplicitlySet = true;
        }
    

    LayoutInflater

    public View inflate(XmlPullParser parser, @Nullable ViewGroup root, boolean attachToRoot) {
            synchronized (mConstructorArgs) {
                ...
                        if (root != null && attachToRoot) {
                            root.addView(temp, params);
                        }
                ...
    
                return result;
            }
        }
    
  • 相关阅读:
    洛谷 P1410 子序列(DP)
    LibreOJ #539. 「LibreOJ NOIP Round #1」旅游路线(倍增+二分)
    LibreOJ #541. 「LibreOJ NOIP Round #1」七曜圣贤(单调队列)
    浴谷八连测R6题解(收获颇丰.jpg)
    数论的一些小结论
    Fence9
    二模 (2) day1
    二模 (1) day2
    二模 (1) day1
    一些编码时的老错误
  • 原文地址:https://www.cnblogs.com/qinhe/p/6370844.html
Copyright © 2011-2022 走看看