LayoutInflater 详解

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 Constructors
LayoutInflater(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 Methods
abstract 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.
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值