11

Possible Duplicate:
How to set android show vertical orientation?

I'm trying to disable auto rotation when I run my application in Android. Maybe, I should add a line code in AndroidManifest.xml Anyone know How can I do that ?

Community
  • 1
  • 1
Anass
  • 5,902
  • 6
  • 26
  • 35

5 Answers5

36

Add something like android:screenOrientation="portrait" or android:screenOrientation="landscape" in the AndroidManifest.xml:

<activity android:name=".MyActivity"
          android:label="@string/app_name"
          android:screenOrientation="portrait">
nhaarman
  • 94,943
  • 53
  • 240
  • 273
4

add a

android:screenOrientation="<mode>" 

attribute to your activity.

see modes here: http://developer.android.com/guide/topics/manifest/activity-element.html#screen

P.Melch
  • 7,836
  • 42
  • 39
1
<activity android:name=".SomeActivity"
              android:label="@string/app_name"
              android:screenOrientation="portrait">

for portrait mode.

Yashwanth Kumar
  • 28,151
  • 14
  • 63
  • 69
1

Add the android:screenOrientation attribute to your <activity /> tag:

<activity android:screenOrientation="landscape" 
          ... >

For further information and a list of possible values visit the documentation.

1

You can make your Activity stay in a single orientation mode by adding the code suggested in the other answers. A more complete way of dealing with this is here:

http://developer.android.com/guide/topics/resources/runtime-changes.html

When you change orientation what you're doing is changing the app configuration. Look under the heading of "Handling the configuration change yourself" section to override the default behaviour.

Graeme
  • 25,374
  • 23
  • 122
  • 184