一、首先看带三个参数的inflate方法:
public View inflate (int resource, ViewGroup root, boolean attachToRoot)
1、如果root不为null,且attachToRoot为TRUE,则会在加载的布局文件的最外层再嵌套一层root布局,这时候xml根元素的布局参数当然会起作用。
2、如果root不为null,且attachToRoot为false,则不会在加载的布局文件的最外层再嵌套一层root布局,这个root只会用于为要加载的xml的根view生成布局参数( 官方原话:If false, root is only used to create the correct subclass of LayoutParams for the root view in the XML.),
这时候xml根元素的布局参数也会起作用了!!!
3、如果root为null,则attachToRoot无论为true还是false都没意义!即xml根元素的布局参数依然不会起作用!
二、再看带两个参数的inflate方法:
public View inflate(int resource, ViewGroup root)
public View inflate (int resource, ViewGroup root, boolean attachToRoot)
1、如果root不为null,且attachToRoot为TRUE,则会在加载的布局文件的最外层再嵌套一层root布局,这时候xml根元素的布局参数当然会起作用。
2、如果root不为null,且attachToRoot为false,则不会在加载的布局文件的最外层再嵌套一层root布局,这个root只会用于为要加载的xml的根view生成布局参数( 官方原话:If false, root is only used to create the correct subclass of LayoutParams for the root view in the XML.),
这时候xml根元素的布局参数也会起作用了!!!
3、如果root为null,则attachToRoot无论为true还是false都没意义!即xml根元素的布局参数依然不会起作用!
二、再看带两个参数的inflate方法:
public View inflate(int resource, ViewGroup root)
查看源码