Android Settings Horizontal Screen vertical screen

Source: Internet
Author: User

Scenario One: Configuring in Androidmanifest.xml

In the project's Androidmanifest.xml, find the activity you specified plus the Android:screenorientation attribute, which has the following parameters:

"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).


Scenario Two: Set in activity code, note that the statement must precede the Setcontentview () method

Set horizontal screen code: setrequestedorientation (Activityinfo.screen_orientation_landscape);//Horizontal screen

because the horizontal screen has two directions, and you are in the execution of the statement to set the horizontal screen, if the screen is not the default horizontal screen direction, will have a horizontal screen rotation of 180 °, to the default horizontal screen direction. If you do not want to continue to change in the case of horizontal screen, you can first determine whether it is a horizontal screen, if it is a horizontal screen, do not execute the statement, the code is as follows:

if (This.getresources (). GetConfiguration (). Orientation ==configuration.orientation_portrait) {      Setrequestedorientation (Activityinfo.screen_orientation_landscape);}

To set up the vertical screen code: setrequestedorientation (activityinfo.screen_orientation_portrait);//Vertical Screen



Android Settings Horizontal Screen vertical screen

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.