1.xml, this is mainly in the androidmanifest.xml to find activity, and then set the property inside, as follows
<application android:label= "@string/app_name" android:icon= "@mipmap/ic_launcher_calculator" > <activity an Droid:name= "Calculator"Android:theme= "@style/calculator.theme"Android:windowsoftinputmode= "Statealwayshidden"<!--screen Settings--
Android:screenorientation= "Portrait"Android:launchmode= "Singletask" > <intent-filter> <action android:name= "Android.intent.action.MAIN"/&G T <category android:name= "Android.intent.category.DEFAULT"/> <category android:name= "android.intent . category. LAUNCHER "/> <category android:name=" Android.intent.category.APP_CALCULATOR "/> </in Tent-filter> </activity> </application>
This property android:screenorientation= "Portrait" has the following properties
"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).
2. Setting in the Code
// Set Horizontal screen setrequestedorientation (activityinfo.screen_orientation_landscape); // setting up a vertical screen setrequestedorientation (activityinfo.screen_orientation_portrait); /* 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-screenorientation screen Settings