Set portrait screen for Android, android

Source: Internet
Author: User

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.

Related Article

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.