Android Adding Alternate Layout Resource Folder

Reading Time: 3 minutes

Responsive design in android programming should have answer on mobile device orientation change from horizontal to vertical (portrait to landscape) and vice versa. In that sense, it is useful to know android adding alternate layout resource folder. So let’s start with new project in Android studio. On empty project design portrait layout in main activity, by adding background image to content_main.xml and putting four image buttons, like this:


Running on real device in portrait mode it looks just fine:


But on the same device in landscape orientation it looks like this:


Not so nice, isn’t it? To prevent this we need to make android alternate layout resource folder. In Android studio, just click as it is shown.


And then choose Create Landscape Variation


Another path for doing the same thing in Android studio is to go to project mode


Then click to app→src→main, then right click, New→Android resource directory.


Then change Resource type to: layout.
Change Available qualifiers to: Orientation.
Click to >>.


And then Screen orientation to: Landscape


In new layout, arrange everything from beginning including background image. Of course, adjust the size of images for image buttons in landscape mode as well.


And application now adjust its appearance automatically to portrait or landscape mode.


You can download Android adding alternate layout resource folder project example

External links:

Android adding alternate layout resource folder on Stackoverflow
Android adding alternate layout resource folder on Developer

Tagged with: ,

Leave a Reply

Your email address will not be published. Required fields are marked *