How to set the desired landscape orientation

I know that you can set the orientation using android: screenOrientation statically and setRequestedOrientation programmatically. However, the problem is that if I use any of them to set the screen orientation, I canโ€™t choose which landscape or portrait I want. To do this, turning the phone 180 degrees, it does not rotate the view, but simply displays upside down for the user. I can not use screenOrientation = "sensor" because in some cases I would like the view to be landscape or portrait, and rarely both. This seems insignificant until you look at external equipment.

If I developed an application and set the layout for Android: screenOrientation = "landscape", the application will display correctly only if the left side of the droid is sitting on the table. Unfortunately, there is a USB port on the left side, so the phone will not sit on this side if it is connected. Unless, of course, they did not use the docking station, but this is not the help I am looking for. If the right side of the phone sits on a table to secure the cord, the display is displayed upside down. I tried to post the image, but as a new user, I could not do it.

I would like to know how to programmatically choose which terrain orientation (Surface.ROTATION_90, Surface.ROTATION_270) or portrait (Surface.ROTATION_0, Surface.ROTATION_180) I want the user to see, but more importantly, do this in the application settings action . I searched Google for quite some time, and all I can find are sensors that tell you when the orientation / rotation has changed and to what, but no one shows how to install it either programmatically.

+3
source share

Source: https://habr.com/ru/post/1775154/


All Articles