Skip to content Skip to sidebar Skip to footer

How To Set Orientation In Two Different Mode , In Two Layout?

I have layout that is called Main.XML and I set the orientation to portrait in my AndroidManifest.xml. I designed this layout for Honeycomb too and placed it in the layout-xlarge-m

Solution 1:

You can place your main.xml in layout-xlarge-land, then it will be used only in landscape orientation Refer Supporting Multiple Screens (Using configuration qualifiers)

Android supports several configuration qualifiers that allow you to control how the system selects your alternative resources based on the characteristics of the current device screen. A configuration qualifier is a string that you can append to a resource directory in your Android project and specifies the configuration for which the resources inside are designed.

Edit: If you provide an main.xml in layout folder and another main.xml in layout-xlarge-land, then

  • for an extra large landscape orientation it will take the main.xml from layout-xlarge-land

  • for all other, that is in landscape or portrait orientation it will take the main.xml from layout

Refer Providing Alternative Resources for more details

Solution 2:

Create a layout-xlarge-mdpi-land folder and place your main.xml in that

Solution 3:

I think this could be done like this:

  1. Detect screen size programmtically in you onCreate. http://www.mail-archive.com/android-developers@googlegroups.com/msg144381.html

  2. Set orientation according to screen size, like this:

    if(screen size is large) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); else setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Not sure if it's the best way though.

Solution 4:

In AndroidManifest insert the following code in whichever activity you want to run in landscape mode(In this case Main Activity)

android:screenOrientation="landscape"

Post a Comment for "How To Set Orientation In Two Different Mode , In Two Layout?"