简体   繁体   中英

Can't use reverse portrait orientation without “Auto-Rotate Screen” enabled

What I'm trying to do

I'm trying to programmatically set the screen orientation to reverse portrait.

Problem

The request to change the screen orientation only works for orientations other than reverse portrait.

What I've Tried

  • Enabling the system-wide "Auto-Rotate Screen" setting seems to allow reverse portrait mode. However, I don't want the app to require that this be enabled in order to work .
  • Both setOrientation and the use of a system dialog to change the orientation. The problem occurs regardless of which method is used.

Other info

I'm developing with a Sony Xperia M (Android 4.1.2).

You can set it in xml in the manifest file using :

android:screenOrientation="reversePortrait"

The similar effect programmatically:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);

More on this here .

Another approach could be to set the rotation of the root layout to 180 degrees. How ever it doesnot rotate the actionbar.

android:rotation="180"

You should use android:screenOrientation="fullSensor" to enable orientation in all 4 orientations, as explained here

EDIT:

Turning 'auto-rotate' off forces the orientation to 'portrait' mode. I am unaware of any way around this without using the manifest.

If auto-rotate is on then initializing the app in 'fullsensor' mode and then changing to 'reverse portrait' based on configuration changes or screen orientation changes will rotate your app to that mode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM