布局充气机有什么用?
我是一名新的 Android 开发人员。我试图从文档中了解布局充气器的使用,但无法理解。 android中布局充气机有什么用?
什么情况下需要使用它?
I'm a new Android developer. I have tried to understand the use of Layout inflator from the documentation but have not been able to understand. what is the use of layout inflator in android?
What are the situations when one would have to use it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更多技术说明
请参阅此,
为简单起见,重新措辞
基本上将您的 xml 平面文件视为没有空气的气球,LayoutInflator 的作用是将其吹胀(或膨胀)成全尺寸的气球,即您的视图和/或视图组。因此,平面文件会膨胀到视图中。 (随意批评这个比喻,但是,这就是我的想法)并且就用法而言,检查 这篇文章出来了。作者谈论了对象的手动膨胀。
对如何实现的解释有些过于简单化。
在内部,映射到 Android.Resource 的缓存子集的 xml 解析器会查找被识别为视图的适用 xml,实例化它们并将它们添加到视图组中。
从哪里看
LayoutInflator 解析 xml 文件并将结果添加到父视图中。查找具有特定签名的重载
其他注意事项
在
LayoutInflater
的注释中为了性能
* 原因,视图膨胀很大程度上依赖于XML文件的预处理
* 这是在构建时完成的。因此,目前还无法
* 在运行时在纯 XML 文件上使用 LayoutInflater 和 XmlPullParser。
因此,我们可以推断文件中的 xml 在编译时被缓存,以减少解析文件所需的处理量。
XmlResourceParser loadXmlResourceParser(String file, int id, int assetCookie, String type)
资源.java。
我希望这能让事情变得更清楚一些。
More Technical Explanation
See this
Reworded for Simplicity
Basically think of your xml flat files as a balloon without air and, what the LayoutInflator does is blows it up (or inflates) into a full sized balloon a.k.a. your Views and, or View groups. So flat file gets inflated into view. (feel free to critique the metaphor but, that is how I think of it anyway) and as far as usage goes check this article out. The author talks about manually inflation of objects.
Somewhat oversimplified explanation of how this is implemented.
Internally an xml parser, that is mapped to a cached subset of the Android.Resource, looks for applicable xml that is recognized as a view instantiates them and adds them to the view group.
Where to look
From that internally
rInflate
in LayoutInflator parses the xml file and adds the result to the parent view. Look for the overload with the specific signatureAdditional things of note
In the comments of
LayoutInflater
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.
So with that we can infer that the xml from the file is cached at compile time to cut the amount of processing required to handle parsing the file.
XmlResourceParser loadXmlResourceParser(String file, int id, int assetCookie, String type)
in the fileResources.java.
this question
I hope this clears things up a bit more.
android中的Layout Inflator是Android中非常重要的一部分
从上图我们可以清楚的看出,
android 系统
这些复杂的操作是什么?
实例化
Inflator 服务
的帮助下,这些对象创建完成并完成。这个过程称为布局膨胀Layout Inflator in android is a very important part of Android
We can clearly see from the above figure,
android system
What are these complex actions ?
instantiation
is made here.
Inflator service
thse object creation is done & this process is calledlayout Inflation