活动在android的动态加载XML布局 [英] Activities loading xml layout dynamically in android

查看:184
本文介绍了活动在android的动态加载XML布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能从存储在设备中的资源(在一个数据库中的资源或部分)装入一个活动的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.

这篇关于活动在android的动态加载XML布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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