The android:screenorientation= "Landscape" attribute can be added to the configuration of Androidmanifest.xml activity (which requires an activity that prohibits steering) (landscape is horizontal, Portrait is a vertical screen). For example:
The code is as follows |
Copy 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, every time the screen switch in Android will restart the activity, so should be in the activities before the destruction of the current active state, in the event again create the load configuration, so that the game will not automatically restart!
To avoid restarting the activity when the screen is turned on, you can redefine the orientation in the Androidmanifest.xml file (add android:configchanges= to each activity) keyboardhidden| Orientation "property) and is controlled according to the activity's rewrite onconfigurationchanged (Configuration newconfig) method so that the activity is not restarted when the screen is turned. Instead, the callback method called Onconfigurationchanged (Configuration newconfig) is invoked. For example
The code is as follows |
Copy Code |
if (Newconfig.orientation==configuration.orientation_landscape) { Horizontal screen Setcontentview (R.layout.file_list_landscape); }else{ Vertical screen Setcontentview (r.layout.file_list); } |
Note that if your screen layout is not the same, then use onconfigurationchanged will cause the layout does not change after the switch, so this setting is carefully used as well.
.