LayoutInfater.inflate之parent

在使用LayoutInflater.inflate方法从一个layout文件时,常用用法:
inflate(int layoutRes, ViewGroup parent, boolean attatchToRoot)
参数详解:

1.layoutRes: layout文件

2.parent: 父view,用于给当前rootView创建LayoutParams,若parent=null, 则layout rootView的所有layout属性(例如layout_width, layout_height都会实效), 而且,给rootView创建的LayoutParams一定是parent的LayoutParams类型,例如当rootView提供了RelativeLayout相关layout属性,而parent是LinearLayout时,RelativeLayout相关属性将会实效

3.attachToRoot: 创建出来的view是否添加到Parent. 参数为true,则将rootView添加到parent, 并返回parent,否则rootView不添加到parent,且返回rootView。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容