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