Scenario One: Configuring in Androidmanifest.xml
In the project's Androidmanifest.xml, find the activity you specified plus the Android:screenorientation attribute, which has the following parameters:
"Unspecified": The default value is determined by the system to determine the direction of the display. The decision strategy is related to the device, so different devices will have different display directions.
"Landscape": Horizontal screen display (width ratio to long)
"Portrait": Vertical display (high width to long)
"User": the current preferred direction for users
"Behind": in the same direction as the activity below the activity (in the activity stack)
"Sensor": there is a physical sensor to decide. If the user rotates the device, the screen will switch between the screens.
"Nosensor": ignores the physical sensor so that it does not change as the user rotates the device (except for the "unspecified" setting).
Scenario Two: Set in activity code, note that the statement must precede the Setcontentview () method
Set horizontal screen code: setrequestedorientation (Activityinfo.screen_orientation_landscape);//Horizontal screen
because the horizontal screen has two directions, and you are in the execution of the statement to set the horizontal screen, if the screen is not the default horizontal screen direction, will have a horizontal screen rotation of 180 °, to the default horizontal screen direction. If you do not want to continue to change in the case of horizontal screen, you can first determine whether it is a horizontal screen, if it is a horizontal screen, do not execute the statement, the code is as follows:
if (This.getresources (). GetConfiguration (). Orientation ==configuration.orientation_portrait) { Setrequestedorientation (Activityinfo.screen_orientation_landscape);}
To set up the vertical screen code: setrequestedorientation (activityinfo.screen_orientation_portrait);//Vertical Screen
Android Settings Horizontal Screen vertical screen