1. Force the screen.
This is done by setting the value of the Android:screenorientation property in the activity in Androidmanifest.xml.
The Android:screenorientation attribute, he has the following several 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).
such as the following settings
android:screenorientation= "Portrait"
Regardless of how the phone changes, the activity with this attribute will be displayed on the vertical screen.
android:screenorientation= "Landscape" for horizontal screen display.
The above modifications can also be set in Java code by code similar to the following
Setrequestedorientation (Activityinfo.screen_orientation_landscape)
2. Do not restart the screen switch
First, the Android:configchanges attribute is set for the corresponding activity in manifest, so that the activity does not continue the above reconstruction process, as follows:
Andorid 3.2 Previous SDK can use the following configuration
Android:configchanges= "Orientation|keyboardhidden"
The SDK after Adnroid 3.2 must add a screensize attribute, as follows
Android:configchanges= "Keyboardhidden|orientation|screensize"
or android:configchanges= "orientation|screensize."
The Screenorientation property has been previously mentioned, and the About Configchanges property setting has the following options:
Value |
Describe |
Mcc |
IMSI Mobile Station Country Code (MCC) changed--a SIM was detected and updated MCC |
Mnc |
IMSI Mobile Station Network Code (MNC) Changes--a SIM is detected and updated MNC |
Locale |
Area changes-The user selects a new language that the text needs to display |
Touchscreen |
The touchscreen has changed. (This usually does not happen.) ) |
Keyboard |
The keyboard type has changed-for example, the user has plugged in an external keyboard. |
Keyboardhidden |
The accessibility of the keyboard changes-for example, the user discovers a hardware keyboard. |
Navigation |
The navigation type (trackball or Dpad) has changed. (This usually does not happen.) ) |
Screenlayout |
Screen layout Changes-this causes different activity to be displayed. |
Fontscale |
The font scaling factor has changed-the user has selected a new font size. |
Uimode |
When the UI pattern changes-when the user places the device to the table or the car or the night mode changes, it can cause UI pattern changes. Read the Uimodemanager. Introduced at API Level 8 o'clock. |
Orientation |
The screen orientation changed-the user rotated the screen. Note: If the application's target API level is 13 or higher (through attribute minsdkversion and attribute targetsdkversion Declaration), you also need to declare the configuration item screensize, as this will change when the device chooses portrait and screen orientation. |
ScreenSize |
The currently available screen size is changed. This represents a change in the current available size, which is related to the current ratio, so when the user chooses a different picture and image, the change occurs. However, if your program target API level is 12 or lower, your activity will always handle this configuration change yourself (this change will not cause the activity to restart, even on Android 3.2 or newer devices). Added in API level 13. |
Smallestscreensize |
Changes in the physical screen size. No matter the direction of change, only in the actual physical screen packaging changes, such as: external display. The change in this configuration item causes a change in Smallestwidth configuration. However, if your program target API level is 12 or lower, your activity will handle the change yourself (this change will not cause the activity to restart, even on Android 3.2 or newer devices) at API level 13. |
LayoutDirection |
Layout direction changes. For example, writing from left-to-right (LTR) to right-to-left (RTL) |
Android (18) Toggle between portrait and screen