Question

Android force Horizontal (landscape) layout

I'm pretty close to finished with my first game for Android, and I've come across a problem that's so simple I'm sure I'll feel stupid for not knowing how to solve it, but how can I force the app to stay in a Horizontal layout? Right now, if you turn the phone (emulator) it flips the graphics and squeezes them. I want the game to start horizontally and stay that way regardless of how the user turns the phone.

Thank you.

 45  76002  45
1 Jan 1970

Solution

 107

Open the AndroidManifest.xml and add the following android:screenOrientation="landscape" e.g.

 <activity android:name=".ActivtyName" 
       android:screenOrientation="landscape"
                >
2010-01-14

Solution

 15

To do this at the Activity level, in case you want to change it dynamically or allow the user to select the orientation, use setRequestedOrientation in your Activity's onCreate method.

this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

etc...

2011-04-26