Switching between the horizontal and vertical screens of android may also cause many problems.
1. Lock the screen direction and disable switching:
Add the Activity parameter in AndroidManifest. xml
Android: screenOrientation = "landscape"
OR
Android: screenOrientation = "portrait" to keep the portrait Screen
2. the Activity will be restarted each time the screen is switched, so it is also prohibited to restart the Activity when the screen is switched, also in AndroidManifest. add the Activity parameter in xml (of course, this is not needed if the screen is locked ~)
Android: configChanges = "keyboardHidden | orientation"
3. When using the simulator, you can use F12 or Ctrl + F11 to switch between the portrait and landscape screens.
4. If you need to adapt the layout to the screen for landscape switching, You can override the onConfigurationChanged (Configuration newConfig) method.
Judge newConfig. orientation = Configuration. ORIENTATION_LANDSCAPE.
Or
NewConfig. orientation = Configuration. ORIENTATION_PORTRAIT
Then, re-setContentView (R. layout. main_XXX) as needed );
5. Add that you can use
SetRequestedOrientation (ActivityInfo. SCREEN_ORIENTATION_LANDSCAPE );
However, this sentence is only applicable in special cases ~