Android layout folders: layout, layout-port, layout-land

AndroidLayoutAndroid Layout

Android Problem Overview


I'm not sure to have understood well the role played by the several Android /res/layout folders.

layout: general layouts

layout-port: layout for widget that must change for portrait orientation

layout-land: layout for widget that must change for landscape orientation

For example in the Home sample application, under layout-port and layout-land folders there is only one home.xml file.

Have I understood right?

Android Solutions


Solution 1 - Android

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.

Solution 2 - Android

If you put home.xml in layout-port folder, when your device is in portrait orientation it will use the file: layout-port/home.xml.

If you put home.xml in layout-land folder, when your device in landscape orientation it will use the file: layout-land/home.xml.

Meaning for different orientation modes like portrait and landscape... we use two home.xml files; one in layout-port and the other in layout-land. If on the other hand you want to use the same layout file for both, you can just put home.xml in the layout folder and remove it from layout-land and layout-port.

Solution 3 - Android

Create folder in res layout-land or layout-port

layout-port: layout for widget that must change for portrait orientation

layout-land: layout for widget that must change for landscape orientation

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGiorgio VespucciView Question on Stackoverflow
Solution 1 - AndroidRobby PondView Answer on Stackoverflow
Solution 2 - AndroidUdaykiranView Answer on Stackoverflow
Solution 3 - AndroidMukesh ChaudharyView Answer on Stackoverflow