活动在android的动态加载XML布局布局、加载、动态、android

2023-09-12 04:35:22 作者:做我的信仰可好

是否有可能从存储在设备中的资源(在一个数据库中的资源或部分)装入一个活动的XML布局文件和动态加载时活动开始了吗?我们的想法是将它从web服务发送到设备。谢谢你。

Is it possible to load an activity's xml layout file from a resource stored in the device (in a db or part of the resources) and load it dynamically when that activity is started ? The idea is to send it to the device from a web service. Thanks.

推荐答案

如果你想夸大,这不是在生成过程中包含一个XML文件,我不认为这是目前可能。这是从Java的文档的 LayoutInflater类的:

If you are trying to inflate a XML file that was not included during the build process I don't think it is currently possible. This is from the java-docs of the LayoutInflater class:

查看android.view.LayoutInflater.inflate(XmlPullParser分析器,   ViewGroup中根,布尔attachToRoot)

View android.view.LayoutInflater.inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot)

充气从指定的XML节点,一个新的视图层次。引发   InflateException如果存在一个错误。

Inflate a new view hierarchy from the specified XML node. Throws InflateException if there is an error.

重要出于性能方面的考虑,鉴于通胀在很大程度上依赖于   pre-处理XML文件完成在构建时。因此,它   目前还不可能使用LayoutInflater与XmlPullParser   在运行时一个普通的XML文件。

Important 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.