布局充气机有什么用?

发布于 2024-10-18 10:43:37 字数 90 浏览 2 评论 0原文

我是一名新的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

画尸师 2024-10-25 10:43:37

更多技术说明

请参阅

为简单起见,重新措辞


基本上将您的 xml 平面文件视为没有空气的气球,LayoutInflator 的作用是将其吹胀(或膨胀)成全尺寸的气球,即您的视图和/或视图组。因此,平面文件会膨胀到视图中。 (随意批评这个比喻,但是,这就是我的想法)并且就用法而言,检查 这篇文章出来了。作者谈论了对象的手动膨胀。

对如何实现的解释有些过于简单化。

在内部,映射到 Android.Resource 的缓存子集的 xml 解析器会查找被识别为视图的适用 xml,实例化它们并将它们添加到视图组中。

从哪里看

LayoutInflator 解析 xml 文件并将结果添加到父视图中。查找具有特定签名的重载

void rInflate(XmlPullParser parser, View parent, final AttributeSet attrs, boolean finishInflate)

其他注意事项

LayoutInflater 的注释中

为了性能
* 原因,视图膨胀很大程度上依赖于XML文件的预处理
* 这是在构建时完成的。因此,目前还无法
* 在运行时在纯 XML 文件上使用 LayoutInflater 和 XmlPullParser。

因此,我们可以推断文件中的 xml 在编译时被缓存,以减少解析文件所需的处理量。

  • 有关如何提取缓存数据的详细视图,请参阅文件中的 XmlResourceParser loadXmlResourceParser(String file, int id, int assetCookie, String type)
    资源.java
  • 有关布局充气器源代码,请参阅 LayoutInflater.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 signature

void rInflate(XmlPullParser parser, View parent, final AttributeSet attrs, boolean finishInflate)

Additional things of note

In the comments ofLayoutInflater

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.

I hope this clears things up a bit more.

只涨不跌 2024-10-25 10:43:37

android中的Layout Inflator是Android中非常重要的一部分


                           _ _ _ _ _ _ _ _ _ _ _ _
                          |                       |
                          |       _____________   |            
                          | Name |_____________|--|-----<2 objects(TextView,EditText)> 
                          |       _____________   |            
                          | Age  |_____________|--|-----<2 objects(TextView,EditText)> 
                          |       _____________   |             
                          | Phone|_____________|--|-----<2 objects(TextView,EditText)> 
                          |                       |
                          |                       |
                          |                       |
                          |                       |
                          |        ------         |         
                          |       |BUTTON| -------|-----<1 objects(ButtonView)>      
                          |        ------         |
                          |                       |
                           -----------------------                           

从上图我们可以清楚的看出,

  • 活动上的UI元素被显示&在用户不可见的活动背后正在发生复杂的操作
    android 系统

这些复杂的操作是什么?

  • 我们可以描述的简单方式是,为 android XML 上存在的每个视图创建对象文件和实例化
  • Inflator 服务 的帮助下,这些对象创建完成并完成。这个过程称为布局膨胀

Layout Inflator in android is a very important part of Android


                           _ _ _ _ _ _ _ _ _ _ _ _
                          |                       |
                          |       _____________   |            
                          | Name |_____________|--|-----<2 objects(TextView,EditText)> 
                          |       _____________   |            
                          | Age  |_____________|--|-----<2 objects(TextView,EditText)> 
                          |       _____________   |             
                          | Phone|_____________|--|-----<2 objects(TextView,EditText)> 
                          |                       |
                          |                       |
                          |                       |
                          |                       |
                          |        ------         |         
                          |       |BUTTON| -------|-----<1 objects(ButtonView)>      
                          |        ------         |
                          |                       |
                           -----------------------                           

We can clearly see from the above figure,

  • The UI elements on the activity are displayed & behind the activity which is not visible for the user complex actions are taking place by
    android system

What are these complex actions ?

  • Simple way we can describe is that, Objects are created for each views that are existing on the android XML file and the instantiation
    is made here.
  • With the help of a Inflator service thse object creation is done & this process is called layout Inflation
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文