1
我想通过LayoutInflater使用外部(如/storage/sdcard0/main.xml)xml作为布局。 所以我发现通过XmlPullParser使用外部xml。但它没有工作!如何通过Android上的XmlPullParser和LayoutInflater使用外部xml?
如何编写在XmlPullParser和LayoutInflater上运行的xml源代码?
我想通过LayoutInflater使用外部(如/storage/sdcard0/main.xml)xml作为布局。 所以我发现通过XmlPullParser使用外部xml。但它没有工作!如何通过Android上的XmlPullParser和LayoutInflater使用外部xml?
如何编写在XmlPullParser和LayoutInflater上运行的xml源代码?
LayoutInflater在运行时不适用于任意xml。请参阅有关LayoutInflater.inflate的评论。
重要由于性能原因,查看通货膨胀在很大程度上依赖于被在编译的时候做的XML文件的预处理。因此,在运行时,通过普通的XML文件使用LayoutInflater和XmlPullParser是不可能的。
该平台在Resources.java中执行了一个downcast,它做出了这个假设。
// 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;
你可以发布你的代码吗? – nio