Android的 - 声明VS编程界面 [英] Android - Declarative vs Programmatic UI

查看:130
本文介绍了Android的 - 声明VS编程界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人见过或编译的对比声明(XML)标准与程序创建UI的Andr​​oid中?

Has anyone seen or compiled benchmarks comparing declarative (XML) versus programmatically created UI's in Android?

有事情,谷歌已经做了加快声明式方法,但你还是必须在运行时完成布局通胀的一步。

There are things that Google has done to speed up the declarative approach, but you still do have the layout inflation step done at runtime.

你有没有交换(或考虑)改变你的用户界面,从声明到编程以任何理由?

Have you ever switched (or considered) changing your UI from declarative to programmatic for any reason?

推荐答案

很少的布局通胀是在运行。由于暗示的LayoutInflator API文档:

Very little of the layout inflation is done at runtime. As hinted in the LayoutInflator API docs:

有关性能方面的原因,查看   通货膨胀在很大程度上依赖于   pre-处理XML文件是   在构建时完成。因此,它是   现在无法使用   LayoutInflater与XmlPullParser   在运行时一个纯XML文件

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

如果你看一下在<一个href="https://android.googlesource.com/platform/frameworks/base/+/b307ceb43fa96e8d54851c20278a4344469c9269/core/java/android/view/LayoutInflater.java">source,很多的意见的基础上他们的XML标记从哈希图拉。

If you take a look at the source, many of the views are pulled from a hash map based on their XML tag.

在回答你的我是否基准充气的问题,我说没有。我个人觉得在基准Android的布局充气您的应用程序是标杆DOM解析器在Firefox为您的网站的等价的想法。我不认为锻炼是没有意义的,但你应该有一个更好的理由不是我的活动布局过于复杂,充气......

In answer to your question of whether I have benchmarked the inflater, I have to say no. Personally I find the idea of benchmarking the layout inflater in Android for your app to be the equivalent of benchmarking the DOM parser in Firefox for your website. I don't think the exercise is pointless, but you should have a much better reason than "my activity layout is too complicated for the inflater"...

如果你需要一个动态生成的布局,你最好关闭编程创建它。如果你认为只是花费很长的时间来充气,你应该简化您的视图的XML。

If you require a dynamically generated layout, you would be best off creating it programmatically. If your view is simply taking a long time to inflate, you should simplify your view XML.

这篇关于Android的 - 声明VS编程界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆