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.
Start by going to Settings => Display and locate the “Device rotation” setting. On my personal cell phone, tapping this will reveal two options: “Rotate the contents of the screen,” and “Stay in portrait view.”
You'll find this setting in the Quick Settings menu. If you see Auto rotate highlighted in blue, then auto rotate is turned on. If you don't see Auto rotate, but there's a Portrait icon instead, auto rotate is disabled. Tap Portrait to turn on auto rotate.
Despite enabling screen auto-rotate on your phone, some apps might refuse to rotate automatically until you tell them to do so. These apps include video players, launchers, etc. They turn off screen auto-rotation by default to minimize distractions and unwanted screen rotations.
Swipe down from the top of your screen to enable "Auto-Rotate," then turn your phone to the side to switch to landscape mode. Turn your phone upright to switch back to portrait mode.
You just need to set the android:screenOrientation
attribute in your AndroidManifest.xml to sensorLandscape
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With