Set portrait screen for Android, android
Solution 1: Configure in AndroidManifest. xml
In AndroidManifest. xml of the project, find the android: screenOrientation attribute in the activity you specified, which has the following parameters:
"Unspecified": The default value is used by the system to determine the display direction. The determined policy is related to the device, so different devices have different display directions.
"Landscape": landscape Display (longer than width/height)
"Portrait": portrait display (height to width)
"User": the user's current preferred direction
"Behind": the direction of the Activity under the Activity is the same (in the Activity stack)
"Sensor": determined by physical sensors. If you rotate the device, the screen will be switched horizontally and vertically.
"Nosensor": Ignore the physical sensor so that it will not be changed as the user rotates the device (except for the "unspecified" setting ).
Solution 2: set it in the Activity code. Note that the statement must be before the setContentView () method.
Set the landscape code: setRequestedOrientation (ActivityInfo. SCREEN_ORIENTATION_LANDSCAPE); // landscape
The horizontal screen has two directions. When you execute the statement to set the horizontal screen, if the screen is not the default horizontal screen direction, the screen that has already been horizontal will be rotated 180 °, to the default horizontal screen direction. If you do not want to change the screen, you can determine whether the screen is landscape. If the screen is landscape, the statement is not executed. The Code is as follows:
if(this.getResources().getConfiguration().orientation ==Configuration.ORIENTATION_PORTRAIT){ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);}
Set the portrait screen code: setRequestedOrientation (ActivityInfo. SCREEN_ORIENTATION_PORTRAIT); // portrait Screen
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.