I would like to have a solution in xml or a keyword for what to search to solve my problem:
I have multiple screens. Each screen has his own xml in layout folder. For eg a part of the code :
<RelativeLayout
android:id="@+id/headerLayout"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:background="@drawable/header" >
<Button
android:id="@+id/btBack"
android:layout_width="55dp"
android:layout_height="33dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dip"
android:layout_marginTop="10dip"
android:background="@drawable/bt_back"
/>
</RelativeLayout>
now, I would like to change the "@drawable/header" value runtime when is a rotation, prefferable to configure and Android change not me in Java code. The same thing is done with
"@drawable/bt_back", which is a bt_back.xml file at drawable folder and has a selector. His content is here:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- selected state -->
<item android:drawable="@drawable/bt_back_pressed" android:state_pressed="true" android:state_selected="false"/>
<item android:drawable="@drawable/bt_back_pressed" android:state_pressed="false" android:state_selected="true"/>
<item android:drawable="@drawable/bt_back_pressed" android:state_pressed="true" android:state_selected="true"/>
<!-- unselected state (default) -->
<item android:drawable="@drawable/bt_back_normal"/>
</selector>
Now in folder what I want drawable-hdpi, drawable-ldpi, I just need to put those 2 files and the android system is auto-handling the image changes for pressed and normal state depending on user device dpi.
The same thing I would like to have for header for rotation from portrait and landscape. Eg it should alternate the header_port.png to header-land.png.
How is possible? Any ideas?
I don’t wand different .xml layout for landscape, nor digg in java code.
Maybe in different folder the resources for header, described here ? port and land?
You are able to create a drawable-land-hdpi directory. Put your landscape versions in the qualified folders and android should automatically load them for you.