I am interested in having an XML layouts in Android change size depending on landscape or portrait viewing (and maybe other configurations later).
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:background="@drawable/stream_bg_1px_wide"
android:layout_height="150dip" >
In this example I just want to vary the 150dip size depending on landscape or portrait, not change anything else.
I am using layout and layout-land, and I know I could repeat the layout in each of those folders, but that makes maintaining changes in it a bit of a pain. When I introduce more variants based on screen density and size it just gets worse.
So, I wondered if it's possible to define a value (constant) in an XML file, and reference it from my layout, similar to how colors can be defined
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="shopper_background"> #FFFFFF</color>
</resources>
along the lines of......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<value name="footer_size" >150</value>
</resources>
Then I could just replicate that file, with different values, in each config.
thanks for any help
Yes you can do this, we do it all over the place in Android itself :) Just define your constants in res/values/, res/values-land/ etc. For dimensions, use the tag and refer to them using @dimen/my_value in the layout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With