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

你可能感兴趣的:(Android学习笔记,android开发)