XML驱动的图形用户界面和性能 [英] XML-driven GUIs and performance

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

问题描述

在线开发人员指南XML的布局,我发现页面下面的语句:

Reading the Online Developer Guide page on XML layouts, I've found the following statement:

您的UI描述是外部应用程序code,这意味着你可以修改或无需修改源$ C ​​$ c和重新编译适应它。

Your UI descriptions are external to your application code, which means that you can modify or adapt it without having to modify your source code and recompile.

我知道XML布局和资源的诸多优点,但由于XML文件都放在里面的APK,我觉得有没有真正的方法来修改GUI没有重新包装。我的意思是,我们大多数人使用的是Eclipse ADT插件和ANT打包的应用程序,所以有未编译的类文件(因为修改资源文件后,没有真正的收益,开发商将不得不重新打包的应用程序,并产生一个新的APK文件)。正因为如此,也没有办法来重新部署只是在设备上图形用户界面,而不重新部署整个APK

I know about the many advantages of XML layouts and resources, but since the XML files are placed inside the APK, I think there's no real way to modify the GUI without repackaging. I mean, most of us are using eclipse ADT plugin and ANT to package the apps, so there's no real gain in not compiling the class files (since after modifying the resource files, a developer will have to repackage the app and produce a new APK file). Because of this, there is no way to redeploy just the GUI on devices without redeploying the entire APK.

如果这一假设是正确的,则XML文件将是一个APK文件的生命周期中是相同的。我想这些文件(特别是布局的)都被解析并在运行时(活动的onCreate之前),这将是比建的GUI编程(如在Swing),低效率的处理。布局通常不是一个瓶颈,但如果我是正确的,我在这里看到的时间浪费小,可以得到更好的使用(比如,用动画)。

If this supposition were true, then XML files are going to be the same during the lifetime of an APK file. I guess these files (specially layout ones) have to be parsed and processed at runtime (before an activity's onCreate) which would be less efficient than building the GUI programmatically (like in Swing). Layout is not usually a bottleneck, but if I'm correct, I see here an small waste of time that could be better used (for instance, with animations).

读同一个页面,它指出:

Reading the same page, it states:

当您编译应用程序时,每个XML布局文件被编译成一个View资源。

When you compile your application, each XML layout file is compiled into a View resource.

检查我的APK之一,我一直在寻找一个precompiled文件中 classes.dex 并没有什么,但我的java类和 R.class 文件。布局XML文件是在 / RES /布局文件夹,这里面的 resources.arsc 这似乎命名的文件包含有关其他资源(字符串,图标名称),但没有涉及到视图的信息,我认为(纠正我,如果我错了)。

Inspecting one of my APKs, I've been looking for a precompiled file inside classes.dex and there's nothing but my java classes and the R.class file. The layout XML files are inside the /res/layout folder, and there's a file named resources.arsc which seems to contain info about other resources (strings, icons names), but nothing related to Views, I think (correct me if I'm wrong).

我的提问:

  • 是XML布局文件precompiled,以及哪些文件?
  • 如果不是,是否有一个编译选项,充分precompile布局信息转化为更快的加载时间的文件? (理想情况下,这将是一个类文件)
  • 如果没有,有没有一种方法创建的第一个执行该文件,并对其进行缓存的应用程序安装文件夹中,以便后续运行时执行可以阅读,而不是解析的XML文件,并具有更快的加载时间?

在此先感谢。

推荐答案

如果您有甘德在类文档的 LayoutInflater ,你会发现他们说:

If you have a gander at the class documentation for LayoutInflater, you'll notice they say:

有关性能方面的原因,查看通货膨胀在很大程度上依赖于pre-处理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.)

所以,是的,布局文件pcompiled在一定程度上确实是$ P $,<删除>,并通过上面的摘录来看,这将是在 R $ layout.class 输出文件(但我不是100%确定的)的precompiled布局文件位于你的编译APK包,因为 / RES /布局/&LT; layout_id&GT;的.xml 。你会发现,如果你将其解压缩,并在大多数纯文本的XML元素都被映射到一些二进制形式的文本编辑器打开它。

So yes, layout files are indeed precompiled to some degree, and, judging by the above excerpt, it would be in the R$layout.class output file (but I'm not 100% sure on that). The precompiled layout file is located in your compiled APK package, as /res/layout/<layout_id>.xml. You'll notice if you extract it and open it in a text editor that most plain-text XML elements have been mapped to some binary form.

这很可能是同一种玉米pression您可以在的Andr​​oidManifest.xml 文件获取打包到的APK看到的。

It would probably be the same kind of compression you can see in AndroidManifest.xml files that get packaged into the APKs.

这篇关于XML驱动的图形用户界面和性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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