I am using two xml layout file layoutPotrait.xml and layoutLandscape.xml.When device/emulator is in portrait mode i want to set the content view with layoutPortrait.xml file and when I will change the emulator to landscape mode I want to set content view with layoutLandscape.xml file. How can I achieve this?
-
If it is working for you please accept the answer through clicking on the check mark left of the upvotes – Janusz May 21 '10 at 11:48
3 Answers
You don't need to know if the device changed. Just provide to layout files for all layouts you want to use in both ways.
If your Android device is in landscape mode and you are loading a layout the android system will look if this layout file exists in the /res/layout-land folder. If it does not exist in this folder it will load the layout from the normal /res/layout folder.
Just name the files the same and put the file that was called layoutPortrait.xml in your /res/layout folder and the layoutLandscape.xml in a /res/layout/land folder. If the folder does not exist create it.

- 187,060
- 113
- 301
- 369
To use different layouts for different orientations, place them in the appropriate folders: see Dev Guide on alternative resources (Screen Orientation section). For more info about changing the layout depending on orientation changes, see this article.

- 9,856
- 2
- 42
- 60
Press Ctrl-F11 or Ctrl-F12 on your keyboard. See Offical manual for more commands and hotkeys.

- 1,597
- 1
- 10
- 21
-
Really thanks, but i want to set the content view with different layout file when i press Ctrl-F12.how can i do this in source code?? – android_novice May 21 '10 at 10:26
-
I linked an article showing an example in my answer above, look for the code with onConfigurationChange. – molnarm May 21 '10 at 10:28
-
yes, what's @android_novice asking is about coding, not about controlling emulator. – anticafe Dec 23 '11 at 04:08