It is possible to include layout and other resources in an Android jar?
I'm building a jar so that other developers can use the view I create in their Android applications. I'm wondering if it is possible to use a 开发者_Go百科layout resource in my jar so I can build the layout of my view or if I need to build up my view programmatically. Similarly, can I include image resources in my jar file?
No, not currently. Because of the way Android packages resources in an apk, you can't include them in a jar. However, you can still share the jar with the other developers - they'll just have to manually pull in the layout files.
NO you cannot you will have to specify the layout parameters within your code for the jar to be of use.
YES you can precompile your xml layout files and put them in the assets/ folder then package them into your jar file, then you can load them using XmlResourceParser and LayoutInflater. Other resource files such as image can also be packaged into jar like this.
精彩评论