Android landscape plan

I am developing an application, and I am just wondering how to make another layout when it is in landscape mode. I created a folder in 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 it already exists, what it does, but is in the "layout" folder. If I call it something else, do I need to change something in the manifest? Thanks for the help!

+7
source share
3 answers

To clarify if you are in landscape or portrait orientation of Android, first it looks for the layout file in the -land directory, if it is not found, it checks the default layout directory. Your files should be named as follows and will be downloaded by the system depending on the runtime in the current device configuration:

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

For more information, see the resource provisioning documentation.

+10
source

You need a folder structure, for example:

 res\layout\main.xml res\layout-land\main.xml 

Each of these layouts should contain the same elements, but reorder, for example. if you have a button with android:id="@+id/button1" in the portrait landscape, you will need to give an equivalent button in landscape mode with the same name.

+1
source

You must first listen for confguration changes by adding to the manifest

 android:configChanges="orientation" 

Then you can override this function and use setContentView

 public void onConfigurationChanged(Configuration newConfig) 
+1
source

All Articles