Technical stuff

Requirements are like water. They're easier to build on when they're frozen.

How to change your layout in Android landscape / portrait mode

25 August 2009 by Georgiana

In the res folder we are used to having a layout folder, in which we keep the XML files which describe our application’s layouts. This trick will show you how to improve the view in landscape or portrait mode, whichever you might need.

How do I quickly change my emulator from portrait to landscape and viceversa?

Use Ctrl + F11 to test around.

Can I only improve the layout and use no extra code?

The short answer is yes, definitely.

The layouts in /res/layout are applied to both portrait and landscape, unless you specify otherwise. Let’s assume we have /res/layout/home.xml for our homepage and we want it to look differently in the 2 layout types.

  1. create folder /res/layout-land (here you will keep your landscape adjusted layouts)
  2. copy home.xml there
  3. make necessary changes to it
  4. run the application in the emulator and test it using the Ctrl + F11 combination

4 comments | Categories: Quick and dirty | Tags: ,

Comments (4)

  1. my app works fine but only in portrait mode, when you rotate the emulator/phone the layout view is wrong, and it doesn’t adjust, i’ve created /res/the layout-land folder and did copy and made adjustments on the layout so everything fits to the landscape layout, Am I missing something? how can I make the app to work on landscape mode also?

  2. nevermind, it works fine, i just changed the name of the copy of main and that’s why it didn’t work, both of the layout.xml files have to be named the same

  3. nice post… i’ve tried and it worked

  4. What necessary changes to be done ?? that you mentioned in 3rd step. I have used files without changing but if says force close