LayoutInflater 详解

来源:互联网 发布:淘宝全屏大图代码 编辑:程序博客网 时间:2024/05/16 10:47

LayoutInflater 类用于初始化一个layout XML file into its corresponding View objects,他不能被直接实例化,只能通过getLayoutInflater()和getSystemService(String)两个方法实例一个标准的instance that is already hooked up to the current context and correctly configured for the device you are running on,

比如

LayoutInflater inflater = (LayoutInflater)context.getSystemService       Context.LAYOUT_INFLATER_SERVICE);
To create a new LayoutInflater with an additional LayoutInflater.Factory for your own views, 
you can use cloneInContext(Context) to clone an existing ViewFactory, 
and then call setFactory(LayoutInflater.Factory) on it to include your Factory. 
构造方法
Protected ConstructorsLayoutInflater(Context context) 
Create a new LayoutInflater instance associated with a particular Context.
LayoutInflater(LayoutInflater original, Context newContext)
Create a new LayoutInflater instance that is a copy of an existing LayoutInflater, optionally with its Context changed
Public Methodsabstract LayoutInflater cloneInContext(Context newContext)
Create a copy of the existing LayoutInflater object, with the copy pointing to a different Context than the original.
final View createView(String name, String prefix, AttributeSet attrs)
Low-level function for instantiating a view by name.
static LayoutInflater from(Context context)
Obtains the LayoutInflater from the given context.
Context getContext()
Return the context we are running in, for access to resources, class loader, etc.
final LayoutInflater.Factory getFactory()
Return the current factory (or null).
LayoutInflater.Filter getFilter() View inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot)
Inflate a new view hierarchy from the specified XML node.
View inflate(int resource, ViewGroup root)
Inflate a new view hierarchy from the specified xml resource.
View inflate(int resource, ViewGroup root, boolean attachToRoot)
Inflate a new view hierarchy from the specified xml resource.
View inflate(XmlPullParser parser, ViewGroup root)
Inflate a new view hierarchy from the specified xml node.
void setFactory(LayoutInflater.Factory factory)
Attach a custom Factory interface for creating views while using this LayoutInflater.
void setFilter(LayoutInflater.Filter filter)
Sets the LayoutInflater.Filter to by this LayoutInflater.
原创粉丝点击