Android sets landscape and landscape.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.