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