Screen direction parameters:
Activityinfo. screen_orientation_unspecified, // Unspecified. This is the default value. The Android system selects the appropriate direction.
Activityinfo. screen_orientation_landscape, // landscape
Activityinfo. screen_orientation_portrait, // portrait Screen
Activityinfo. screen_orientation_user ,//
User's current preferred direction
Activityinfo. screen_orientation_behind, // inherits the direction of the activity under the current activity in the activity Stack
Activityinfo. screen_orientation_sensor, // The display direction is determined by the physical sensor.
Activityinfo. screen_orientation_nosensor ,//
Ignore the physical sensor-that is, the display direction is irrelevant to the physical sensor.
Activityinfo. screen_orientation_sensor_landscape,
Activityinfo. screen_orientation_sensor_portrait,
Activityinfo. screen_orientation_reverse_landscape,
Activityinfo. screen_orientation_reverse_portrait,
Activityinfo. screen_orientation_full_sensor,
You can use setrequestedorientation (activityinfo. screen_orientation_unspecified) to specify the screen direction.
ExampleCode:
31. dynamically change the screen direction
/If it is a vertical bar, it is changed to a horizontal bar.
If (getrequestedorientation () = activityinfo. screen_orientation_landscape)
{
Setrequestedorientation (activityinfo. screen_orientation_portrait );
}
// If the row is horizontal, it is changed to vertical
Elseif (getrequestedorientation () = activityinfo. screen_orientation_portrait)
{
Setrequestedorientation (activityinfo. screen_orientation_landscape );
}
Set the default direction in the androidmanifest. xml file.
<Activity Android: Name = ". changeorientation"
Android: Label = "@ string/app_name"
Android: screenorientation = "portrait">
32. Prevent the oncreate operation from being re-executed after the screen Rotation
You only need to add attributes to the activity configuration file:
Android: configchanges = "orientation | keyboardhidden | navigation"
You can overload the onconfigurationchanged method in the activity and perform other actions according to different rotation directions, as shown below:
@ Override
Public void onconfigurationchanged (configurationnewconfig ){
Super. onconfigurationchanged (newconfig );
}