To support different resolutions, we need to make variations of layout files as described in Supporting Multiple Screens very well. Assuming you don’t plan to show different arrangement of your UI but just want to stretch appropriately, your variations would be mostly about different weights. At least that is the case with my app so far.
Now, how do you manage changing the application with this structure? Since it repeats the layout many times, one layout change in your application causes multiple files change.
I thought of two options:
- Changing the values dynamically in your code
- Downside is your layout related work is spilled over to the code. I really don’t like this.
- Making child layout to extract common layout elements
- Downside is your layout’s hierarchy will be deeper and cluttered so it would be harder to figure out what’s going on. Still, this is better than option #1 thanks to Hierarchy Viewer. I am not sure if this approach will be always achievable.
If you could share your tricks to get through this, it would be much appreciated.
I think I found a solution. I will accept it as an answer if others give thumbs up.
I found Configuration qualifiers described in Supporting Multiple Screens works not only for
res/drawableandres/layoutbut also forres/values. So on mylayout/some_layout.xml, I say like this:Then on
values/layout.xmlfile you define the defaultbutton_size:And on
values-xlarge/layout.xmlfile you define the xlarge modebutton_size:I didn’t try other
valuesresources, but I assume it also works for Styles and Themes so in case your layout customization is a little bit more than a size or weight, you could define a style in the values and use it.