Android sets landscape and landscape.
Method 1: Configure in AndroidManifest. xml
If you do not want the software to switch between the horizontal and vertical screens, the easiest way is to do so in the AndroidManifest of the project. in xml, add the android: screenOrientation attribute to the activity you specified. It has the following parameters:
"Unspecified": The default value is determined by the system. the determined policy is related to the device, so different devices have different display directions. "landscape": landscape Display (longer than width) "portrait": landscape Display (longer than width) "user": your preferred direction "behind ": consistent with the direction of the Activity under the Activity (in the Activity stack) "sensor": there is a physical sensor to decide. 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 ).
Method 2: Set in java code
Set the landscape code: setRequestedOrientation (ActivityInfo. SCREEN_ORIENTATION_LANDSCAPE); // landscape
Set the portrait screen code: setRequestedOrientation (ActivityInfo. SCREEN_ORIENTATION_PORTRAIT); // portrait Screen
Because the horizontal screen has two horizontal methods, and this setting of the horizontal screen statement, if it is not the default horizontal screen direction, the screen has been rotated 180 °.
Therefore, you can determine whether the screen is landscape. If you do not rotate it again, it will not make the user feel inexplicable! The Code is as follows: if (this. getResources (). getConfiguration (). orientation = Configuration. ORIENTATION_PORTRAIT) {setRequestedOrientation (ActivityInfo. SCREEN_ORIENTATION_LANDSCAPE );}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.