1. Setting the screen orientation
When the orientation of the screen is specified (not screen_orientation_unspecified), the screen does not rotate itself actively
There are 2 ways to control the screen orientation:
1.1 Change androidmanifest.xml
added to the activity of Androidmanifest.xml:Horizontal screen:
android:screenorientation= "Landscape" vertical screen: android:screenorientation= "Portrait"
1.2 setrequestedorientation
Horizontal screen:
Setrequestedorientation (Activityinfo.screen_orientation_landscape);
Vertical screen:
Setrequestedorientation (activityinfo.screen_orientation_portrait);
Activityinfo:
int |
screen_orientation_behind |
constant corresponding to behind in the screenorientation attribute. |
int |
screen_orientation_full_sensor |
constant corresponding to fullsensor  IN THE  screenorientation attribute. |
int |
screen_orientation_full_user |
constant corresponding to fulluser in the screenorientation attribute. |
int |
screen_orientation_landscape |
constant corresponding to landscape in the screenorientation attribute. |
int |
screen_orientation_locked |
constant corresponding to locked in the screenorientation attribute. |
int |
screen_orientation_nosensor |
constant corresponding to nosensor in the screenorientation attribute. |
int |
screen_orientation_portrait |
constant corresponding to portrait in the screenorientation attribute. |
int |
screen_orientation_reverse_ LANDSCAPE |
constant corresponding to reverselandscape  IN THE  screenorientation attribute. |
int |
screen_orientation_reverse_ PORTRAIT |
constant corresponding to reverseportrait  IN THE  screenorientation attribute. |
int |
screen_orientation_sensor |
constant corresponding to sensor in the screenorientation attribute. |
int |
screen_orientation_sensor_ LANDSCAPE |
constant corresponding to sensorlandscape  IN THE  screenorientation attribute. |
int |
screen_orientation_sensor_ PORTRAIT |
constant corresponding to sensorportrait  IN THE  screenorientation attribute. |
int |
screen_orientation_unspecified |
constant corresponding to unspecified  IN THE  screenorientation attribute. |
int |
screen_orientation_user |
constant corresponding to user in the screenorientation attribute. |
int |
screen_orientation_user_ LANDSCAPE |
constant corresponding to userlandscape  IN THE  screenorientation attribute. |
Int |
Screen_orientation_user_portrait |
Constant corresponding to userportrait in the screenorientation attribute. |
2. Disable screen rotation and reset activity
The activity.oncreate method is forced to be called after the screen is rotated, so the Activity is reset
Forbidden Method:
Change androidmanifest.xml
android:configchanges= "Orientation"
recent Android player. After encountering the above method, the screen rotation still occurs after the trigger activity.oncreate, screensize handling
The detailed code is:
Android:configchanges= "Orientation|keyboardhidden|screensize"
Disable reset activity will cause screen to be turned upside-down and need to be manually corrected.
Android Set Horizontal screen, disable screen rotation, activity reset [Update Video player related]