Reputation: 1987
I want to force my Android app into lanscape orientation. I managed to do that by adding screenOrientation
in AndroidManifest.xml
like this:
<activity android:name="SomeActivity"
android:label="@string/app_name"
android:screenOrientation="landscape">
or by adding the following line in the onCreate
function of my only Activity
:
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
The problem is that both the solutions above disables rotation. How do I force landscape but allow rotation? I want to be able to rotate the phone 180 degrees. From landscape to the other landscape.
Upvotes: 7
Views: 4419
Reputation: 467
You just need to set the android:screenOrientation
attribute in your AndroidManifest.xml to sensorLandscape
Upvotes: 12
Reputation: 4821
Refer to this link http://developer.android.com/reference/android/R.attr.html#screenOrientation
For your activity, set the attribute as sensorLandscape
This enables to have the screen in landscape orientation, but can use the sensor to change which direction the screen is facing. Corresponds to SCREEN_ORIENTATION_SENSOR_LANDSCAPE.
Code sample
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
Upvotes: 5