建筑/使用生成的运行Android中的布局XML [英] Building/using runtime generated layout XML in Android

查看:170
本文介绍了建筑/使用生成的运行Android中的布局XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的要求我使用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.

这篇关于建筑/使用生成的运行Android中的布局XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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