开发者

Android - generated layouts, is it possible?

is it possible in Android c开发者_StackOverflow社区reate dynamic layouts and then use them? I mean insted of layouts defined in src use some dynamic generated layouts from database, which contains pieces of XML code and when put together it makes new layout...

It is real or unreal scenario?


That is not supported. The built-in LayoutInflater requires resource files, not arbitrary XML. Quoting the documentation:

Therefore, it is not currently possible to use LayoutInflater with an XmlPullParser over a plain XML file at runtime; it only works with an XmlPullParser returned from a compiled resource (R.something file.)

You would have to write your own LayoutInflater equivalent.


you can create elements programatically. For instance you can do:

TextView myTextView = new TextView();

You may have to do something like this. Otherwise you will need to generate an XML file and use LayoutInflater I guess.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜