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
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.
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.
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.
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.
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