0

I am sure this question has been asked a few times but I am not able to find the answer on stackoverflow.com

What I need is that there be 2 layout files activity_main_pot.xml activity_main_land.xml Based on the orientation

How to achieve this?

  • Check this question : http://stackoverflow.com/questions/4858026/android-alternate-layout-xml-for-landscape-mode – Dalmas Jun 23 '13 at 09:23

2 Answers2

1

Just name both layout files with the same name (like activity_main.xml) and just put the landscape one in your res/layout-land folder (create the folder if it doesn't exist). The rest is done for you automatically by the framework.

Plato
  • 2,338
  • 18
  • 21
  • Not working I get a exception at setContentView. java.lang.RuntimeException http://pastebin.com/xFm8U1jV –  Jun 23 '13 at 10:52
  • Which error do you get? – Plato Jun 23 '13 at 10:53
  • I debugged and this error comes at setContentView in onCreate. Do I have to add anythin in my mainfest xml? –  Jun 23 '13 at 10:58
  • It says in your log that you pasted that you have to set a layout_width on line 82 of your xml. So check your xml and make sure that every view has height and width set. – Plato Jun 23 '13 at 10:59
0

My Dear Friend, it's a very simple. Android Use to render the whole screen on changing the layout. if the phone/device is in landscape then it first check the layout in folder "layout-land", if it is not then it draws from the layout folder and vice versa.

Solution: Just Create another folder "layout-land" and paste your landscape layout file in this folder. And same file name with portrait layout in "layout" folder. It will work :)