Android attachToRoot对于LayoutInfl
2020-02-20 本文已影响0人
周_0717
View inflate(@LayoutRes int resource, @Nullable ViewGroup root, boolean attachToRoot)方法为加载视图时常用的方法,但是当attachToRoot值为true当时候返回当时root,否则为resource对应当视图。
关键代码在 View inflate(XmlPullParser parser, @Nullable ViewGroup root, boolean attachToRoot)方法开始部分:
View result = root;
以及结束部分:
// Decide whether to return the root that was passed in or the
// top view found in xml.
if (root == null || !attachToRoot) {
result = temp;
}
2020-02-20