简体   繁体   中英

Android. How to determine screen orientation if application supports only portrait mode?

My Android application works only in portrait orientation. Landscape mode is disabled with

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT). 

But i have a dialog with a signature view (custom view) and a user uses it for drawing his signature. It gives a bitmap as a result. I also have an ImageView for saved signature preview which displays the bitmap described above. A user can hold his device as he wants while drawing a signature. So, my application should rotate resulting bitmap according to current screen position. For instance, a user draws his signature with angle = 90 degrees and i want to rotate the bitmap at 90 degrees and my application will display the signature bitmap in portrait mode properly. The problem is that only portrait mode is supported and the following approaches doesn't work:

int rotation = getResources().getConfiguration().orientation;

or

int rotation = getWindowManager().getDefaultDisplay().getOrientation();

The result for these statements is always 0.

So, how i can get a current position of device in case an orientation changing is disabled?

您可以将对话框设为单独的活动,并且不限于纵向。

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