panthro
panthro

Reputation: 24061

Android, landscape only orientation?

How can I make it so the screen orientation is always landscape?

Do I need to add something to the manifest.xml?

Upvotes: 57

Views: 134237

Answers (6)

SHAH MD IMRAN HOSSAIN
SHAH MD IMRAN HOSSAIN

Reputation: 2889

When you are in android studio 3 or above you need to add following lines AndroidManifest.xml file

<activity
            android:name=".MainActivity"
            android:configChanges="orientation"
            android:screenOrientation= "sensorLandscape"
            tools:ignore="LockedOrientationActivity">

One thing this is sensor Landscape, means it will work on both landscape sides

But if you only want to work the regular landscape side then, replace sensorLandscape to landscape

Upvotes: 4

Pottercomuneo
Pottercomuneo

Reputation: 787

One thing I've not found through the answers is that there are two possible landscape orientations, and I wanted to let both be available! So android:screenOrientation="landscape" will lock your app only to one of the 2 possibilities, but if you want your app to be limited to both landscape orientations (for them whom is not clear, having device on portrait, one is rotating left and the other one rotating right) this is what is needed:

android:screenOrientation="sensorLandscape"

Upvotes: 12

user1087919
user1087919

Reputation:

You can try with

 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Upvotes: 0

Hoo
Hoo

Reputation: 1840

Just two steps needed:

  1. Apply setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); after setContentView().

  2. In the AndroidMainfest.xml, put this statement <activity android:name=".YOURCLASSNAME" android:screenOrientation="landscape" />

Hope it helps and happy coding :)

Upvotes: 11

DRiFTy
DRiFTy

Reputation: 11369

Add this android:screenOrientation="landscape" to your <activity> tag in the manifest for the specific activity that you want to be in landscape.

Edit:

To toggle the orientation from the Activity code, call setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) other parameters can be found in the Android docs for ActivityInfo.

Upvotes: 104

Sean Owen
Sean Owen

Reputation: 66876

Yes, in AndroidManifest.xml, declare your Activity like so: <activity ... android:screenOrientation="landscape" .../>

Upvotes: 16

Related Questions