I’ve run into a dilemma when working with apps that should support a large range of screen sizes. What is the best way to scale attributes like text size, width and height via styles?
Optimally, I would love a setup like this:
layout.xml:
<YourView style="@style/Footer"/>
styles.xml:
<style name="Footer">
<item name="android:layout_height">@string/FooterHeight</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:background">@drawable/background_footer</item>
<item name="android:layout_gravity">bottom</item>
</style>
values/layout_vals.xml:
<string name="FooterHeight">50dp</string>
values-sw600dp/layout_vals.xml:
<string name="FooterHeight">80dp</string>
Then, in order to change the height of a View, all one would have to do is create a new folder with the target min width and edit the values of *layout_vals.xml*, and leave all the extraneous junk about width, gravity, background etc alone, leaving for a much cleaner setup and easier editing.
However, I’ve tried and found out that this exact setup doesn’t work. For now, I just copy the entire styles.xml into the different ‘layout-swXXdp’ folders and swap out values. Does anyone have suggestions as to another method of project setup that is comparable to or, better yet, even better than this? Thank you for your time!
Instead of string, use the @dimen resource – I think its exactly what you’re looking for (except it would go into res/values-sw600dp)