1. Setting the screen orientation
When the orientation of the screen is specified (not screen_orientation_unspecified), the screen does not rotate automatically
There are 2 ways to control the screen orientation:
1.1 modifying androidmanifest.xml
in Androidmanifest.xml's activity, add: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  attribute. |
|
int |
screen_orientation _sensor |
constant corresponding to sensor  IN THE  screenorientation attribute. |
|
int |
screen_orientation _sensor_landscape |
CONSTANT CORRESPONDING TO  sensorLandscape  IN THE  attribute. |
|
int |
screen_orientation _sensor_portrait |
CONSTANT CORRESPONDING TO  sensorPortrait  IN THE  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  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:
Modify androidmanifest.xml
android:configchanges= "Orientation"
Android Set Horizontal screen, disable screen rotation, activity reset