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: Configchanges= "Orientation|keyboardhidden" after the
after the screen switch will not go to execute oncreat function, but will call Onconfigurationchanged (), So we can control the switching of the screen.
or the Layout-land and Layout-port directories are created in the Res directory, the corresponding layout files are 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 in the code Setrequestedorientation (Activityinfo.screen_orientation_landscape);.
If you want it to always be a vertical display, just set android:screenorientation= "Portrait" in the configuration file,
or setrequestedorientation in your code ( activityinfo.screen_orientation_portrait);.
When you start a horizontal screen, the horizontal screen, the vertical screen of the vertical screen, mobile phone switching screen can not be used.
First step: Append android:screenorientation= "sensor" android:configchanges= "Orientation|keyboardhidden" to Mainfest.xml
Step Two: 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 >=else= 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 get it back from another screen, and then re-screen layout,
As long as in the Onresume () in the setting, but this only supports the screen only one layout.
Android Screen Summary