inflate用一个XML源填充view. LayoutInflater
2013-08-15 17:01
239 查看
android.view.LayoutInflater
This class is used to instantiate layout XML file into its corresponding View objects.
It is never be used directly --
use getLayoutInflater() or getSystemService(String) to retrieve a standard LayoutInflater instance
that is already hooked up to the current context and correctly configured for the device you are running on.
For example:
LayoutInflater inflater = (LayoutInflater)context.getSystemService
Context.LAYOUT_INFLATER_SERVICE);
常用方法有:
public View inflate (int resource, ViewGroup root)
Since: API Level 1
Inflate a new view hierarchy from the specified xml resource. Throws InflateException if there is an error.
Parameters
resource ID for an XML layout resource to load (e.g., R.layout.main_page)
root Optional view to be the parent of the generated hierarchy.
Returns
* The root View of the inflated hierarchy. If root was supplied, this is the root View; otherwise it is the root of the inflated XML file.
注意:如果root被提供的话,在把新生成的View连接到root后,返回root.否者返回的是新生成的View
public View inflate (int resource, ViewGroup root, boolean attachToRoot)
Since: API Level 1
Inflate a new view hierarchy from the specified xml resource. Throws InflateException if there is an error.
Parameters
resource ID for an XML layout resource to load (e.g., R.layout.main_page)
root Optional view to be the parent of the generated hierarchy (if attachToRoot is true), or else simply an object that provides a set of LayoutParams values for root of the returned hierarchy (if attachToRoot is false.)
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.
Returns
* 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.
注意:如果root被提供而且attachToRoot为TRUE的话,在把新生成的View连接到root,返回root.否者返回的是新生成的View。
如果root被提供但attachToRoot为FALSE的话,root只是把它的LayoutParams参数给新生成的View用,
不会把新生成的View连接到root。当然返回的是新生成的View。
相关文章推荐
- inflate用一个XML源填充view. LayoutInflater
- inflate用一个XML源填充view. LayoutInflater
- Android LayoutInflater.inflate(int resource, ViewGroup root, boolean attachToRoot)的参数理解
- [Android]inflate方法与 findViewById 方法区别 | LayoutInflater的inflate函数用法详解
- The difference between LayoutInflater.inflate and findViewById
- 源码分析初级《篇一》 为何建议使用LayoutInflater.from而不用View.inflate
- 采用layoutInflater打气筒创建一个view对象 →ListView
- Android LayoutInflater.inflate(int resource, ViewGroup root, boolean attachToRoot)的参数理解
- Avoid passing null as the view root convertView = infalInflater.inflate(R.layout.list_item, null);
- LayoutInflater 的inflate(int resource, ViewGroup root, boolean attachToRoot)方法研究
- LayoutInflater.from(this) View.inflate()
- Android自定义View开篇之(LayoutInflater.inflate()详解)
- LayoutInflater和inflate()方法的用法 (自定义View中加载xml布局)
- LayoutInflater.inflate方法加载View
- View.Inflate)与LayoutInflater.from().inflate();
- View.inflate和LayoutInflater的inflate方法区别
- LayoutInflater.from(this)的用法--inflate就相当于将一个xml中定义的布局找出来.
- (转)View.inflate和LayoutInflater的inflate方法区别
- android学习之LayoutInflater的用法,在myAdapter getView()里将多个TextView组件压缩成一个View控件,并在listView里显示
- LayoutInflater.inflate()调用后View的构造方法和onFinishInflate()方法执行的顺序