Reading the Online Developer Guide page on XML layouts, I've found the following statement:
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.
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.
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:
When you compile your application, each XML layout file is compiled into a View resource.
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).
My questions:
- Are XML layout files precompiled, and to which file?
- If not, is there a compilation option to fully precompile layout info into a file for faster load time? (ideally, this would be a class file)
- If not, is there a way to create that file in the first execution and cache it on the application installation folder, so that subsequent runtime executions can read that file instead of parsing the XML and have a faster load time?
Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…