Question

I am creating demo app for tablet and also for mobile device.
Now there is one activity which has two tabs,So inside tab there is ListView.
My Question is I want to show that ListView by some margin from left and right.So as orientation changes that margin value also changes
I have read docs from developer side according to that Following is code snips for listview.
inside res/layout-xlarge-land folder

<ListView
    android:id="@+id/android:list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="250dp"
    android:layout_marginRight="250dp" >
</ListView>


inside res/layout-xlarge-port folder

  <ListView
    android:id="@+id/android:list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="100dp"
    android:layout_marginRight="100dp" >
</ListView>


Now problem is that when i change orientation of tablet it only takes portrait mode xml file and not landscape xml file. So how to resolve this problem.
also included in manifeast file
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" />
<supports-screens android:anyDensity="true" android:resizeable="true"/>
and for activity included
android:configChanges="orientation|screenSize"

Was it helpful?

Solution

try

layout-sw600dp-land for landscape mode in 7" tablet

layout-sw600dp-port for portrait mode in 7" tablet

layout-sw720dp-land for landscape mode in 10" tablet

layout-sw720dp-port for portrait mode in 10" tablet

OTHER TIPS

You need to remove the android:configChanges="orientation|screenSize" line from your manifest. This stops the activity being destroyed and recreated.

Without it the OS will automatically destroy the activity and recreate it with the layout for the new orientation.

If you don't want to destroy it automatically you can catch the onConfigurationChanged() event and set the layout again manually there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top