我想使用外部(如/storage/sdcard0/main.xml)xml 作为 LayoutInflater 的布局。 所以我发现 XmlPullParser 使用外部 xml。但它没有用!!
如何编写运行在XmlPullParser和LayoutInflater上的xml源码?
最佳答案
LayoutInflater 在运行时不适用于任意 xml。查看关于 LayoutInflater.inflate 的评论.
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.
平台在 Resources.java 中执行向下转换做出这个假设。
// XXX note that for now we only work with compiled XML files.
// To support generic XML files we will need to manually parse
// out the attributes from the XML file (applying type information
// contained in the resources and such).
XmlBlock.Parser parser = (XmlBlock.Parser)set;
关于android - 如何在 Android 上通过 XmlPullParser 和 LayoutInflater 使用外部 xml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19754031/