Android开发————LayoutInflater翻译

LayoutInflater:

英文原文:

Instantiates a layout XML file into its corresponding View objects. It is never used directly. Instead, use getLayoutInflater() orgetSystemService(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);

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.

For performance reasons, view inflation relies heavily on pre-processing of XML files that is done at build time. Therefore, it is not currently possible to use LayoutInflater with an XmlPullParser over a plain XML file at runtime; it only works with an XmlPullParser returned from a compiled resource (R.something file.)


将XML布局文件实例化成对应的View对象。它从来不直接使用,取而代之的是,使用getLayoutInflater()或者getSystemService(String) 去重新获得已经挂载在当前Context上,并且已经成功配置好在设备商正常运行的标准实例化LayoutInflater。例如:

LayoutInflater inflater = (LayoutInflater)context.getSystemService
      (Context.LAYOUT_INFLATER_SERVICE);
为了创建一个带有 LayoutInflater.Factory 新的 LayoutInflater视图,可以使用cloneInContext(Context)去克隆一个已经存在的ViewFactory,然后调用etFactory(LayoutInflater.Factory) 将它包含在自己的Factory中。

由于效率的缘故,视图的inflation非常依赖于XML文件在建立时间内预处理速度。因此,目前不可能通过使用一个带有XmlPullPares的LayoutInflater在运行期间来解析一个XML布局;它只能在XmlPullPareser返回一个已经编译好的资源的时候才能工作,如R.something file

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值