Issue
I am a newbie android developer. Recently I am reading Google's specification of providing alternative resources to support different screen size.
https://developer.android.com/training/multiscreen/screensizes.html
I know we can provide resource directories with specific qualifiers to achieve this,
e.g. layout-sw320dp/layout.xml,layout-sw480dp/layout.xml, layout-sw600dp/layout.xml.
Meanwhile, I also found some developers who create variousdimens.xml in the values folders with different screen size qualifiers,
e.g. values-sw320dp/dimens.xml , values-sw480dp/dimens.xml, values-sw600dp/dimens.xml.
I am wondering which approach would be better for maintaining the layout. My intuition told me if I have controlled the screen size rendering by different layout.xml. Then I do not need to use dimens.xml to fit different screen size. Is it a right thought?
Solution
You should use dimens.xml if the only thing changing is the size. You should use layout.xml if you're changing the actual views.
Why? Because of maintenance. If in 3 months you decide you want to change the background color of a view and you have 4 layout files, you need to go and change it in 4 places. Eventually you'll forget one. If you used dimens properly, you only need to change it in 1 place.
Prefer to use dimens wherever possible.
Answered By - Gabe Sechan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.