简体   繁体   English

理论问题:在 Android 中加载外部 XML-Layout 文件

[英]Theoretical question: load external XML-Layout file in Android

I thinks it's probably not possible for security reason but just want to be sure: is it possible to create layout in Android from an external XML file?我认为出于安全原因这可能是不可能的,但只是想确定:是否可以从外部 XML 文件在 Android 中创建布局?

To be exactly: I'm creating XML output with XSL on a remote server.确切地说:我正在远程服务器上使用 XSL 创建 XML output。 I could create the necessary layout direct on the server and then download it to my Android App.我可以直接在服务器上创建必要的布局,然后将其下载到我的 Android 应用程序中。

It is impossible.是不可能的。 XML layouts in Android are NOT stored as XML. Android 中的 XML 布局不存储为 XML。 For performance reasons, they are pre-processed during compilation and stored in binary form, and layout inflater only understands that binary form rather than xml.出于性能原因,它们在编译期间被预处理并以二进制形式存储,并且布局膨胀器只理解二进制形式而不是 xml。

Of course you can create Views dynamic at runtime, while I'm not shure, that this is the best solution.当然,您可以在运行时动态创建视图,但我并不认为这是最好的解决方案。 If you have a look at the internals of Android, every View which is created through XML is called with a Constructor with two parameters: Context and - even more interesting for you - an AttributeSet .如果您查看 Android 的内部结构,则通过 XML 创建的每个 View 都使用带有两个参数的 Constructor 调用:Context 和 - 对您来说更有趣 - 一个AttributeSet I think you have a lot of work with parsing it, while keeping track of the right format.我认为您在解析它时需要做很多工作,同时还要跟踪正确的格式。 You could at least set the values and build your views yourself in Java depending on Server output.您至少可以根据服务器 output 在 Java 中设置值并自己构建视图。

YES, right now is possible with ItsNat Droid, take a look:是的,现在可以使用 ItsNat Droid,看看:

https://groups.google.com/forum/#!topic/itsnat/13nl0P12J_s https://groups.google.com/forum/#!topic/itsnat/13nl0P12J_s

It is still under heavy development but most important features are already implemented.它仍在大力开发中,但最重要的功能已经实现。

Maybe the inflate function of the LayoutInflator works for you.也许 LayoutInflator 的充气 function适合你。

EDIT : doesn't work yet it seems.编辑:似乎还不行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM