Method One: Configure in Androidmanifest.xml
If you do not want the software to switch between the two screens, the simplest way is to find in the project Androidmanifest.xml you specify the activity in addition to the Android:screenorientation attribute, he 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).
Method Two: Set in Java code
Set Horizontal screen code:setrequestedorientation (Activityinfo.screen_orientation_landscape);//Horizontal screen
Set up the vertical screen code: setrequestedorientation (activityinfo.screen_orientation_portrait);//Vertical screen
Because the horizontal screen has two direction of the horizontal method, and this setting horizontal screen of the statement, if not the default horizontal screen direction, will have a horizontal screen rotation of 180 °.
So you can first determine whether it has been horizontal screen, if not rotated, will not let the user feel the turn of the inexplicable! The code is as follows:
if (this.getresources (). GetConfiguration (). Orientation ==configuration.orientation_portrait) {setrequestedorientation (activityinfo.screen_orientation_landscape);}
Android Setting horizontal Screen vertical screen