Solution to Android horizontal and vertical screen Switching

Source: Internet
Author: User
During Game Development, some games can only be played on a horizontal screen. Therefore, when mobile phones are erected and placed, the game screen must be kept on a horizontal screen. To do this, you can simply configure it in androidmanifest. xml. Add this line to Android: screenorientation = "Landscape ". (Landscape is horizontal, and portrait is vertical) <? 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, in Android, the activity is restarted every time the screen is switched. 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! You can add the Android: configchanges = "keyboardhidden | orientation" attribute to each activity without restarting the activity. instead, call onconfigurationchanged (configuration newconfig ). in this way, you can adjust the display mode in this method. For example, if (newconfig. orientation = configuration. orientation_landscape) {// transverse setcontentview (R. layout. file_list_landscape);} else {// vertical setcontentview (R. layout. file_list );}
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.