During Android development, the onconfigurationchanged event is triggered when the screen changes from Portrait evaluation to landscape evaluation by default. By default, the screen is reloaded and the screen is the same as the landscape evaluation, there will be two problems,
Layout problems, the layout displayed on the portrait screen is changed to the landscape screen because of the width and height. All the changes will affect the layout (unless you create two sets of scenes and then add a judge how to display them on the Landscape screen, how to display the image on the portrait screen), of course, the simplest way is to use the androidmanifest in the project. find the activity you specified in XML and add it
If only the portrait screen is displayed (Android: screenorientation = "portrait ")
For horizontal screen display only (Android: screenorientation = "Landscape ")
Picture re-loading problem: by default, the screen will be re-loaded during horizontal and vertical switching, leading to unnecessary resource waste, and more serious is the data maintained on the screen (especially for Games) it also has been reset (of course you can save the data to the database or to a text file before the reset), how to avoid re-loading the screen during horizontal/vertical switching,
First, you must find Android: configchanges = "orientation | keyboardhidden" in your specified activity in androidmanifest. xml"
Then, in the logic processing of the activity (CodePart) to reload the onconfigurationchanged event. For more information about the code, see (Note: The following code does not change the screen when switching between landscape and portrait screens, and is processed as portrait screens.):
@ Override public void onconfigurationchanged (configuration config) {try {super. onconfigurationchanged (newconfig); If (this. getresources (). getconfiguration (). orientation = configuration. orientation_landscape) {// code to be processed during landscape screen display. // The code here is setrequestedorientation (activityinfo. screen_orientation_portrait);} else if (this. getresources (). getconfiguration (). orientation = configuration. orientation_portrait) {// code setrequestedorientation (activityinfo. screen_orientation_portrait);} catch (exception ex ){}}
You can simply control the display mode of your app screen and the screen will not be reloaded when the display mode remains unchanged, that is, your app is optimized and the user experience is improved accordingly.
We hope to help you. Haha.