建筑/使用生成的运行Android中的布局XML布局、建筑、Android、XML

2023-09-03 22:31:35 作者:永不→放弃

我目前工作的要求我使用XML文档在Android设备上渲染一个项目。该表格​​必须取出,并在运行时显示。我想知道如果有一种方法来标记形式的XML,使用XSLT转换为Android的布局XML转换,然后让设备呈现它。

I am currently working on a project which requires me to use an XML document to render a form on an Android device. The form must be fetched and displayed at run-time. I am wondering if there is a way to tag the form XML, transform it using XSLT into an Android layout XML, and then have the device render it.

推荐答案

不幸的是,你不能只是复制LayoutInflater或使用其他类似的技巧来做到这一点 - 布局通胀是完全依赖于视图构造它采取的AttributeSet参数,这是完全依赖于Context.obtainStyledAttributes方法,它本身是完全依赖于具有$ P $对 - 处理二进制XML文件,以便能够做到相当有效的属性的分辨率。

Unfortunately you can't just clone LayoutInflater or use other such tricks to do this -- layout inflation is entirely dependent on the view constructors which take an AttributeSet argument, which are entirely dependent on the Context.obtainStyledAttributes method, which itself is entirely dependent on having a pre-processed binary XML file to be able to do reasonably efficient attribute resolution.

您可以探索的另一种方法是在服务器上使用AAPT工具(或者更可能的是被攻击的版本),为您生成布局编译成相应的数据。不幸的是,我们目前没有办法去构造从原始二进制数据的XmlPullParser(它必须得到这个BLOB从AssetManager),因此工作相当数量上做客户端和服务器使用这种方法。我怀疑人们可以想出一些pretty的整齐,但是这将是大量的工作。

An alternative approach you can explore is to use the aapt tool (or more likely a hacked version of it) on your server, to compile the layouts you generate into the appropriate data. Unfortunately we don't currently have a way to contruct an XmlPullParser from a raw binary blob (it must get this blob from the AssetManager), so there is a fair amount of work to do on both the client and server with this approach. I suspect one can come up with something pretty neat, but it will be lots of work.