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-mdpi
folder, but I want to use the Main.XML
in layout-xlarge-mdpi
only in landscape orientation.
Now, how can do this?
Thanks
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
Create a layout-xlarge-mdpi-land
folder and place your main.xml
in that
I think this could be done like this:
Detect screen size programmtically in you onCreate. http://www.mail-archive.com/android-developers@googlegroups.com/msg144381.html
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.
In AndroidManifest insert the following code in whichever activity you want to run in landscape mode(In this case Main Activity)
android:screenOrientation="landscape"