onFinishInflate() 跟踪

onFinishInflate() 跟踪基于android4.4.1:/***FinalizeinflatingaviewfromXML.Thisiscalledasthelastphase*ofinflation,afterallchildviewshavebeenadded.**Evenifthesubclassov

基于android 4.4.1:

    /**
     * Finalize inflating a view from XML.  This is called as the last phase
     * of inflation, after all child views have been added.
     *
     * <p>Even if the subclass overrides onFinishInflate, they should always be
     * sure to call the super method, so that we get called.
     */
    protected void onFinishInflate() {
    }

在layoutInflate类中, inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot) 会调用到 rInflate(XmlPullParser parser, View parent, final AttributeSet attrs, boolean finishInflate),

/**
     * Recursive method used to descend down the xml hierarchy and instantiate
     * views, instantiate their children, and then call onFinishInflate().
     */
    void rInflate(XmlPullParser parser, View parent, final AttributeSet attrs,
            boolean finishInflate) throws XmlPullParserException, IOException

r代表递归,该方法将以递归向下(其实就是DFS)的顺序实例化view,在将某个view的全部子孙view都实例化完以后,会调用该view的onFinishInflate()。

只有子view全部都实例化以后,我们在该view的onFinishInflate()函数中才能使用findViewById(id)找到id对应的子view实例。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/38608.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注