1. LayoutInflater 对象获取的三种方式
LayoutInflaterinflater=LayoutInflater.from(this);
LayoutInflaterinflater=getLayoutInflater();
LayoutInflaterinflater=(LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
2. LayoutInflater 参数说明
public View inflate(int resource, ViewGroup root, boolean attachToRoot){
}
* @param resource ID for an XML layout resource to load (e.g.,
* <code>R.layout.main_page</code>)
布局文件ID
@param root Optional view to be the parent of the generated hierarchy (if
<em>attachToRoot</em> is true), or else simply an object that
* provides a set of LayoutParams values for root of the returned
* hierarchy (if <em>attachToRoot</em> is false.)
可选的参数,如果第三个参数attachToRoot为true那么该对象是生成的View的父容器,
并把生成的View最 为子View加入到该View中;
如果第三个参数attachToRoot为false该参数只提供一个根布局参数给生成的View
* @param attachToRoot Whether the inflated hierarchy should be attached to
* the root parameter? If false, root is only used to create the
* correct subclass of LayoutParams for the root view in the XML.
配合第二参数一起工作
* @return The root View of the inflated hierarchy. If root was supplied and
* attachToRoot is true, this is root; otherwise it is the root of
* the inflated XML file.
如果第二参数有传递并且第三个参数值为true,那么返回的是第二个参数传递进来的View
否则返回的是从xml文件创建的View
本文详细介绍了Android开发中LayoutInflater对象的三种获取方式及inflate()方法的参数说明和返回值,帮助开发者深入理解如何在应用程序中高效地加载布局文件。
175

被折叠的 条评论
为什么被折叠?



