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