开发者

Parameterize an xml layout

开发者 https://www.devze.com 2023-03-29 07:36 出处:网络
I have a \"complex\" xml with some layouts inside. For example LinearLayout LinearLayout TextView (title)

I have a "complex" xml with some layouts inside. For example

LinearLayout
         LinearLayout
               TextView (title)
               ImageView
         LinearLayout
               TextView
               TextView
         LinearLayout
               TextView
               ImageView (icon)

In my application I need to reuse that block but changing some attributes (for example the title and icon) leaving the rest untouched.

Is posible to declare that parameters in the XML and change those attributes in the include po开发者_Go百科int? Or I must make it programmatically at the onCreate/onResume/inflate of the view?

Thanks


Bonjour Caroline,

you need to inflate a static xml and change programmaticaly the dynamic parts. Use ids to retrieve the widgets you want to modify and change their properties after inflating.

Also, you could consider using other layouts, nested linear layouts tends to be slower and less effective than a big relative layout for all components.

Regards, Stéphane

0

精彩评论

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

关注公众号