Disable horizontal screen/portrait switching for Android

Source: Internet
Author: User

In AndroidProgramThe interface is always in one direction and does not change with the phone direction: you only need to configure it in androidmanifest. xml.

Add the Android: screenorientation = "Landscape" attribute to the androidmanifest. XML activity (activity that requires no redirection) configuration (landscape is horizontal and portrait is vertical ). For example:

 

<? XML version = "1.0" encoding = "UTF-8"?> <Manifest xmlns: Android = "http://schemas.android.com/apk/res/android" package = "com. ray. linkit "Android: versioncode =" 1 "Android: versionname =" 1.0 "> <application Android: icon =" @ drawable/icon "Android: label = "@ string/app_name"> <activity Android: Name = ". main "Android: Label =" @ string/app_name "Android: screenorientation =" portrait "> <intent-filter> <action Android: Name =" android. intent. action. main "/> <category Android: Name =" android. intent. category. launcher "/> </intent-filter> </activity> <activity Android: Name = ". gameplay "Android: screenorientation =" portrait "> </activity> <activity Android: Name = ". optionview "Android: screenorientation =" portrait "> </activity> </Application> <uses-SDK Android: minsdkversion =" 3 "/> </manifest>

 

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 use the function in androidmanifest. in the XML file, redefine the direction (add the Android: configchanges = "keyboardhidden | orientation" attribute to each activity), and control it based on the onconfigurationchanged (configuration newconfig) method of the activity, in this way, the activity will not be restarted during screen conversion, but the onconfigurationchanged (configuration newconfig) Hook method will be called. For example:

 

 
If (newconfig. Orientation = configuration. orientation_landscape) {// transverse setcontentview (R. layout. file_list_landscape);} else {// vertical setcontentview (R. layout. file_list );}

In the simulator, you can use the shortcut key F12 or Ctrl + F11 to switch the program to the screen. Of course, you can use the receivemulator.exe-skin HVGA-L directly to start the horizontal screen program when using the command line to start the simulator.

Related Article

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.