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 = 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

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.