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
  • 6,132
  • 6
  • 27
  • 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
  • 98,571
  • 55
  • 246
  • 278
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
  • 8,066
  • 43
  • 40
1
<activity android:name=".SomeActivity"
              android:label="@string/app_name"
              android:screenOrientation="portrait">

for portrait mode.

Yashwanth Kumar
  • 28,931
  • 15
  • 65
  • 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,714
  • 24
  • 124
  • 186