Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The xml is not switching when device orientation change

Tags:


I have made two folders, res/layout and res/layout-land

The output i got
If I start the application in portrait mode, it will always use the xml in layout folder if the application run in portrait mode. And will not use xml in layout-land if i change the device to landscape mode
If it start in landscape mode it only use the xml in layout-land
The xml is not switching when the orientation change

What i expect was
It should use the xml in layout folder while it is in portrait mode and use the xml in layout-land while in landscape mode

In the Manifest file i have added android:configChanges="orientation" for the activity and

<supports-screens          android:resizeable="true"         android:largeScreens="true"         android:normalScreens="true"         android:anyDensity="true" /> 

Did i missed any thing here? What changes i need to do here?
Thank You

like image 202
Labeeb Panampullan Avatar asked Dec 28 '10 07:12

Labeeb Panampullan


People also ask

How do I make an XML document landscape?

Step 1: Open the base UI layout in DESIGN mode so that you see the actual GUI, such as Buttons, icons, etc. Step 2: Click the icon marked in the below screenshot and, from the menu, select Create Landscape Variation. Then the corresponding Landscape file will be created automatically named as land\xml file name.

What happens when orientation changes Android?

When you rotate your device and the screen changes orientation, Android usually destroys your application's existing Activities and Fragments and recreates them. Android does this so that your application can reload resources based on the new configuration.

What is orientation in Android XML?

The screen orientation attribute is provided by the activity element in the Android Manifest. Xml file. The orientations provided by the activity are Portrait, Landscape, Sensor, Unspecified and so on. To perform a screen orientation activity you define the properties in the Android Manifest.


1 Answers

The manifest code

android:configChanges="orientation|screenSize" 

ignores the XML in "layout-land" and uses the one in the "layout" folder. If you create a different XML for landscape don't use the android:configChanges="orientation|screenSize" tag for that activity.

like image 82
Siddharth Lele Avatar answered Oct 03 '22 00:10

Siddharth Lele