Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Force landscape orientation but allow rotation

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.

like image 873
user1766169 Avatar asked Jan 24 '15 21:01

user1766169


People also ask

How do I force an Android app to rotate?

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.”

How do I rotate my screen when an app doesn't rotate?

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.

Why do some apps not allow screen rotation?

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.

How do I force my phone to landscape?

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.


2 Answers

You just need to set the android:screenOrientation attribute in your AndroidManifest.xml to sensorLandscape

like image 140
Joe Hackerberg Avatar answered Oct 21 '22 00:10

Joe Hackerberg


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);
like image 35
Prem Avatar answered Oct 21 '22 00:10

Prem