Android in the question of the screen

Source: Internet
Author: User

First, the direction of the screen can be implemented in the Androidmanifest.xml file by setting the Screenorientation property, Screenorientation is used to specify the direction that activity is displayed on the device, each value represents the following meanings:

"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 user's current preferred orientation

"Behind"

is in the same direction as the activity below the activity (in the activity stack)

"Sensor"

There are physical sensors to decide. If the user rotates the device, the screen will switch between the screens.

"Nosensor"

The physical sensor is ignored so that it does not change as the user rotates the device (except for the "unspecified" setting).

Second, rotate the screen call OnCreate () method:

Workaround:

Specifies the android:configchanges= "keyboardhidden|orientation|screensize" property for activity in the Androidmanifest.xml file. The OnCreate () function is not called again when the screen is turned, but instead calls Onconfigurationchanged ().

Note: If the development API level is equal to or higher than 13,screensize must be set, because screensize will change when the screen rotates

Third, monitor the screen rotation events, for the screen direction to do some action:

Overriding the Onconfigurationchanged (Configuration newconfig) method

@Override Public voidonconfigurationchanged (Configuration newconfig) {Super. onconfigurationchanged (Newconfig); if( This. Getresources (). GetConfiguration (). Orientation = =Configuration.orientation_landscape) {            //what to do on a horizontal screenLOG.I ("screen orientation", "horizontal screen"); }Else{            //What you need to do with the vertical screenLOG.I ("screen orientation", "vertical screen"); }    }

Android in the question of the 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.