开发者

Preferred method for XML layouts: explicit attributes or styles.xml?

开发者 https://www.devze.com 2023-01-21 02:43 出处:网络
Currently I\'m mixing explicit attributes (layout_width, height, alignment) on my various XML layouts with coded styles in styles.xml, plus outsourcing colors from colors.xml.

Currently I'm mixing explicit attributes (layout_width, height, alignment) on my various XML layouts with coded styles in styles.xml, plus outsourcing colors from colors.xml.

From your experience, what's the recommended开发者_JS百科 way to organize an android app's layouts?


Usings styles is way more organized and makes the xml code easier to read, I think that the visual editor for layouts sucks, so the best way to edit is still to manual edit text the file. Easier reading is a big plus.

I use style anywhere im repeating layouts, something that is very useful is that any explicits attributes will override those of the style, so you can use styles and if what you need is almost the same, you just explicitly redifine the attribute.

Any time you need to fix a layout issue you can update the style and not need to update it a million times.

On the other hand if you are just using that layout "style" once, there is no reason to write an actual style for it, just do it all explicitly.

0

精彩评论

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