Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android landscape layout

I'm designing an app and I was just wondering how to make a different layout when in landscape mode. I created a folder in the res called "layout-land" and created an xml file but it does not work when I run the emulator. I tried calling it "main" but it says that already exists, which it does but in the "layout" folder. If I call it something different do I need to change something in the manifest? Thanks for the help!

like image 870
Ryan Sayles Avatar asked May 11 '12 13:05

Ryan Sayles


People also ask

How do I manage portrait and landscape on Android?

To create the landscape mode right click on the res folder -> New -> Android Resource Directory. Now one pop up will be prompted. Select Orientation Available Qualifiers and then “>>” icon at right side, then select Landscape under Screen Orientation.

How do I force horizontal orientation on Android?

Open the AndroidManifest. xml and add the following android:screenOrientation="landscape" e.g. Show activity on this post. To do this at the Activity level, in case you want to change it dynamically or allow the user to select the orientation, use setRequestedOrientation in your Activity's onCreate method.


1 Answers

Just to clarify, if you are in landscape or portrait Android looks for the layout file in either the -land directory first, if it's not found then it checks the default layout directory. Your files should be named as follows, and will be loaded by the system depending at runtime on the device's current configuration:

res/layout/main.xml
res/layout-land/main.xml

Check the documentation on providing resources for more information.

like image 150
Alex Lockwood Avatar answered Sep 30 '22 05:09

Alex Lockwood