1

我想使用外部(如 /storage/sdcard0/main.xml)xml 作为 LayoutInflater 的布局。所以我发现 XmlPullParser 使用外部 xml。但它没有工作!

如何编写在 XmlPullParser 和 LayoutInflater 上运行的 xml 源代码?

4

1 回答 1

3

LayoutInflater 在运行时不适用于任意 xml。请参阅LayoutInflater.inflate上的评论。

重要 出于性能原因,视图膨胀在很大程度上依赖于在构建时完成的 XML 文件的预处理。因此,目前无法在运行时在纯 XML 文件上使用带有 XmlPullParser 的 LayoutInflater。

平台在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;
于 2013-11-03T17:00:28.350 回答