Share the correct implementation mode of Android horizontal and vertical screen Switching

Source: Internet
Author: User

One of the main reasons why everyone is very interested in the Android mobile operating system is that it is an open-source operating system. You can make simple changes to the system to meet your specific needs. Next we will introduce in detail how to switch between the horizontal and vertical screens of Android.

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 ".

For example, if landscape is horizontal and portrait is vertical ):

Android horizontal and vertical screen switching ava code

 
 
  1. < ?xml version="1.0" encoding="utf-8"?>   
  2. < manifest xmlns:android="http://schemas.android.com/apk/res/android"   
  3. package="com.ray.linkit"   
  4. android:versionCode="1"   
  5. android:versionName="1.0">   
  6. < application android:icon="@drawable/icon" android:label="@string/app_name">   
  7. < activity android:name=".Main"   
  8. android:label="@string/app_name"   
  9. android:screenOrientation="portrait">   
  10. < intent-filter>   
  11. < action android:name="android.intent.action.MAIN" />   
  12. < category android:name="android.intent.category.LAUNCHER" />   
  13. < /intent-filter>   
  14. < /activity>   
  15. < activity android:name=".GamePlay"   
  16. android:screenOrientation="portrait"> 
  17. < /activity>   
  18. < activity android:name=".OptionView"   
  19. android:screenOrientation="portrait"> 
  20. < /activity>   
  21. < /application>   
  22. < uses-sdk android:minSdkVersion="3" />   
  23. < /manifest> 

In addition, the Activity is restarted every time the screen is switched on 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!

This section describes how to implement horizontal and vertical screen switching for Android.

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.