Reputation: 6839
i have a list adapter for my list. the list item is created by inflating a layout which has a relative layout with 50dp height. i want to change the height of the relative layout to be wrap content on orientation landscape and in portrait it be 50 dp. how can i achieve this?
Upvotes: 0
Views: 414
Reputation: 25143
Create one folder in the res
folder called layout-land
for landscape mode. Inside that folder rewrite your xml file with height as wrap-content. In the xml of layout folder keep the height as 50 dp.
Example: let say you have relative layout in abc.xml
inside res\layout
as given:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="50">"
<!--Other code -->
</RelativeLayout >
Create abc.xml
inside res\layou-land
as given below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content">"
<!--Other code -->
</RelativeLayout >
If you are in landscape or portrait Android looks for the layout file in either the -port or -land directory first, if it's not found then it falls back to the default layout directory.
You can read about providing alternative resources here. There are many more options than just land and port.
Upvotes: 0
Reputation: 2555
you can create two different layouts file, put the portrait layout in res/layout/ folder and the landscape layout on res/layout-land folder.
Upvotes: 1
Reputation: 25793
Define another layout with the same name in /layout-land
and change layout_height
to wrap content.
Upvotes: 1