LayoutInflater性能 [英] LayoutInflater Performance

查看:310
本文介绍了LayoutInflater性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android的参考,它说:

In Android reference, it says

有关性能方面的原因,查看通货膨胀在很大程度上依赖于
  $ P $的XML文件对处理是在编译时完成。因此,它
  目前不可能使用LayoutInflater与XmlPullParser
  在运行时一个普通的XML文件;它只能与XmlPullParser
  从已编译的资源返回(R.something文件。)

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.)

细节这里

如果它真的会导致性能原因,Android开发不解决这个问题呢?这是关于它的任何解决方案?我之前充气布局文件使用XML解析器?

if it really causes performance reasons why Android developers don't solve this problem? Is it any solution about it? Can I use a XML parser before inflate layout file?

推荐答案

Android的字符串处理速度很慢。因此,他们实际上做由pre-处理XML文件解决它。当你想想看,你的布局XML的应该是静态的,因为你对他们所做的任何更改将最有可能还会造成code的变化。什么是能够膨胀的远程布局文件,如果特别是当字符串处理是你不能使用它,而code变化的一点是缓慢的。

Android's string processing is slow. So they actually do solve it by pre-processing the xml file. When you think about it, your layout xmls should be static cause any change you made on them will most likely also cause code changes. What is the point of being able to inflate a remote layout file if you can't use it without code changes especially when the string processing is that slow.

有一个更好的解决方案可能是,编写会创建所需的布局的类文件,把它放在什么地方可以说互联网。不是在运行时,你可以下载该文件,动态使用反射加载它作为一类,并使用它。

A better solution might be, writing a class file that creates the layout you need, put it in somewhere lets say internet. Than on the runtime you can download that file, load it as a class dynamically using reflection and use it.

看看这个链接获取更多信息。

Check out this links for further information.

Java反射 - 动态类加载和重新加载

<一个href=\"http://stackoverflow.com/questions/3022454/how-to-load-a-java-class-dynamically-on-android-dalvik?rq=1\">How动态地加载Java类在Android / Dalvik的?

这篇关于LayoutInflater性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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