How to create a layout file programmatically
I was wondering if it were possible to dynamically create an XML layout file to be display开发者_StackOverflow社区ed to the user. The idea would be to be able to retrieve a layout file from a central server, which could display this dynamic, server driven GUI.
XML layout files are packaged as binary and the inflation occurs from binary as well. I don't believe that arbitrary XML can be used for layout.
You'll have a problem with the way resource IDs are pre-baked at build time.
Since GUI elements can be instantiated at runtime, you could probably roll your own inflater with an XML parser and a bit of reflection.
精彩评论