ScreenOrientation and screenorientation

Source: Internet
Author: User

ScreenOrientation and screenorientation

<Activity android: name = ". MyActivity"
Android: label = "@ string/app_name"
Android: screenOrientation = "portrait">


Android: screenOrientation: sets the direction of the activity. The value can be any of the following strings:

"Unspecified"
-Default value: select the display direction from the system. The display direction may vary with devices.

"Landscape"
-Forward Direction

"Portrait"
-Portrait

"User"
-Use the current preferred direction of the cursor

"Behind"
-Same direction as the activity under the activity Stack

"Sensor"
-The direction is determined based on the physical direction sensor. It depends on the direction in which the camera is used. When the camera is used to rotate the device, it changes with the camera.

"Nosensor"
-The direction is determined without the physical direction sensor. the sensor is ignored. Therefore, when the device is rotated using the secondary node, the display will not change with the secondary node. except for this difference, the system chooses to use the same policy orientation for "unspecified" settings. the system selects the same display direction based on "unspecified" ("unspecified.


Its implementation in code: for example

SetRequestedOrientation (ActivityInfo. SCREEN_ORIENTATION_LANDSCAPE); // force the screen to be landscape
SetRequestedOrientation (ActivityInfo. SCREEN_ORIENTATION_PORTRAIT); // force the portrait Screen


After switching between the horizontal and vertical screens, the Activity will re-execute the onCreat function, but in the Mainfest. after android: screenOrientation = "user" android: configChanges = "orientation | keyboardHidden" is added to xml, the OnCreat function will not be executed after horizontal and vertical screen switching, instead, we will call onConfigurationChanged (), so that we can control the switching between the landscape and landscape screens.
Or create the layout-land and layout-port directories under the res directory, and the corresponding layout files remain unchanged. Layout-land is the layout of the horizontal screen, and layout-port is the layout of the 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.