inflater.inflate一共有4个方法java
inflate(@LayoutRes int resource, @Nullable ViewGroup root) inflate(@LayoutRes int resource, @Nullable ViewGroup root, boolean attachToRoot) inflate(XmlPullParser parser, @Nullable ViewGroup root) inflate(XmlPullParser parser, @Nullable ViewGroup root, boolean attachToRoot)
上面两个方法就是将解析XML调用下面两个对应的方法。spa
public View inflate(@LayoutRes int resource, @Nullable ViewGroup root) { return inflate(resource, root, root != null); }
public View inflate(XmlPullParser parser, @Nullable ViewGroup root) { return inflate(parser, root, root != null); }
咱们经常使用的方法就是上面两个。code
若是没有root返回的view将不会设置LayoutParams。class
若是有root,attachToRoot为false的话就会将root的LayoutParams设置给view并返回的view。方法
若是有root,attachToRoot为true的话就会将view添加到root中并返回已添加view的root。view