Horizontal and vertical screen switching for Android

Source: Internet
Author: User

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 ~

 


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.