A androidmanifest.xml file setting
1. By default, the activity call is rebuilt when the screen rotates oncreate
You can add settings to the corresponding activity
android:configchanges= "orientation|screensize"//individual settings orientation may not be valid
When the screen changes, the activity is not rebuilt and the onconfigurationchanged is called.
@Override public void onconfigurationchanged (Configuration newconfig) { //newconfig.orientation;//get screen status //CONFIGURATION.ORIENTATION_LANDSCAPE//2 Horizontal //configuration.orientation_portrait//1 Vertical Super.onconfigurationchanged (Newconfig); }
2. Force fixed activity display direction, ignoring machine auto-rotation function
android:screenorientation= "Landscape"//Horizontal
android:screenorientation= "Portrait"//Vertical
Screenorientation a total of 7 selectable values (constants defined in the Android.content.pm.ActivityInfo Class):
Landscape: Horizontal screen (landscape photo), the width of the display is greater than the height;
Portrait: Vertical screen (portrait), the height of the display is greater than the width;
User: The current preferred direction for users;
Behind: Inherits the active direction of the activity below the activity stack;
Sensor: The physical sensor determines the direction of the display, depending on how the user holds the device, and when the device is rotated, the direction changes-between the horizontal screen and the vertical screen;
Nosensor: Ignoring physical sensors-that is, the display direction is independent of the physical sensor, no matter how the user rotates the display direction of the device will not change (except for the "unspecified" setting);
Unspecified: Unspecified, this is the default value, by the Android system to choose the appropriate direction, the selection strategy depends on the configuration of the specific device, so different devices will have a different direction choice;
Two-Write code call function
1. Force fixed activity display direction (same as setting android:screenorientation effect)
Call the Setrequestedorientation function in activity
Setrequestedorientation (Activityinfo.screen_orientation_landscape);//Cross
Setrequestedorientation (activityinfo.screen_orientation_portrait);//Vertical
this
.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
Android Screen and Webcam