Android Screen Summary (GO)
The activity will re-execute the Oncreat function after the screen switch, but add the android:screenorientation= "user" Android to the Android project Mainfest.xml: After configchanges= "Orientation|keyboardhidden", after the screen switch will not go to execute the Oncreat function, but will call Onconfigurationchanged (), So we can control the switching of the screen.
or in the Res directory to establish the Layout-land and Layout-port directory, the corresponding layout file is unchanged. Layout-land is the horizontal screen of the layout,layout-port is the vertical screen layout.
If you want it to always be a horizontal display, just set android:screenorientation= "Landscape" in the configuration file, or setrequestedorientation in the code ( Activityinfo.screen_orientation_landscape);. If you want it to always be a vertical display, just set android:screenorientation= "Portrait" in the configuration file, or setrequestedorientationin the code ( activityinfo.screen_orientation_portrait);.
When the start is horizontal screen, the horizontal screen, vertical screen, the vertical screen, mobile phone switching screen can not be used.
Step One: Append android:screenorientation= "sensor" android:configchanges= "to the Mainfest.xml"orientation| Keyboardhidden"
The second step: Get the length and width of the screen, and compare the variables to set the screen.
Display display = Getwindowmanager (). Getdefaultdisplay ();
int width = display.getwidth ();
int height = display.getheight ();
if (width > height) {
orientation = Activityinfo.screen_orientation_landscape;
} else {
orientation = activityinfo.screen_orientation_portrait;
}
Step Three: Append This.setrequestedorientation (morientation) to the onconfigurationchanged () function.
@Override
public void onconfigurationchanged (Configuration newconfig) {
Super.onconfigurationchanged (Newconfig);
This.setrequestedorientation (morientation);
}
When you cut to another frame, you return to the original screen, it is still horizontal or vertical. Want to let it back from another screen, and then re-screen layout, as long as in the Onresume () in the settings on the line, but this only supports the screen only one layout.
Android Screen Summary (GO)