Android: alternate layout xml for landscape mode


Question

How can I have one layout for landscape and one for portrait? I want to assume extra width and conserve vertical space when the user rotates the phone over sideways.

1
117
2/1/2011 1:32:27 AM

Accepted Answer

By default, the layouts in /res/layout are applied to both portrait and landscape.

If you have for example

/res/layout/main.xml

you can add a new folder /res/layout-land, copy main.xml into it and make the needed adjustments.

orientation

See also http://www.androidpeople.com/android-portrait-amp-landscape-differeent-layouts and http://www.devx.com/wireless/Article/40792/1954 for some more options.

210
10/5/2012 11:34:57 PM

In the current version of Android Studio (v1.0.2) you can simply add a landscape layout by clicking on the button in the visual editor shown in the screenshot below. Select "Create Landscape Variation"

Android Studio add landscape layout


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon