You canConfigure screen discovery in androidmanifest. xml. Add this line to <activity> Android: screenorientation = "Landscape/portrait"
In Android, the activity is restarted when the screen is switched. You can save the status of the current activity before the activity is destroyed and load the configuration when the activity is created again, in progress, the game will not automatically restart)
When the screen changes to a horizontal screen, the system will callOncreateMethod, you can put the following method in your oncreate to check the current direction, and then let your setcontentview load different layout XML.
If (this. getresources (). getconfiguration (). Orientation = configuration. orientation_landscape ){
Log. I ("info", "Landscape ");
}
Else if (this. getresources (). getconfiguration (). Orientation = configuration. orientation_portrait ){
Log. I ("info", "portrait ");
}
In addition, the activity is restarted every time the screen direction is switched in Android. Therefore, you should save the status of the current activity before the activity is destroyed and load the configuration when the activity is created again, in progress, the game will not automatically restart! To avoid restarting the activity during screen conversion, you can re-define the direction in the androidmanifest. xml file (addAndroid: configchanges = "keyboardhidden | orientation"Attribute), and control it based on the override onconfigurationchanged (configuration newconfig) method of the activity, so that the activity will not be restarted during screen conversion, but will call onconfigurationchanged (configuration newconfig) this Hook method.
Why?Android: configchanges = "orientation" is not supported? I only use "orientation" and will still call the oncreate method.