我想知道是否可以在运行时从未编译的 Android XML 布局文件中扩充 Android Activity ?
最佳答案
API 中没有内置任何内容可以让您执行此操作。 Inflater 需要一个拉解析器来处理已编译的 XML 文件。作为通货膨胀处理的一部分,系统会处理很多事情,例如资源绑定(bind)。来自 the documentation for LayoutInflater
:
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; it only works with an XmlPullParser returned from a compiled resource (R.something file.)
我想您可以构建自己的 XML 处理程序并自己完成,但这需要大量工作。
关于android - 我可以从未编译的 android XML 中扩充 android Activity 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13080695/