In Android to let a program's interface always maintain a direction, not with the mobile phone rotation and change the way: As long as the androidmanifest.xml inside the configuration can be.
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 longitudinal). For example:
<?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 and roid:icon= "@drawable/icon" android:label= "@string/app_name" > <activity android:name= ". Main "android:label=" @string/app_name "android:screenorientation=" Portrait "> <intent-filt er> <action android:name= "Android.intent.action.MAIN"/> <category "android:name=" Nt.category.LAUNCHER "/> </intent-filter> </activity> <activity android:name=". GamePlay "android:screenorientation=" Portrait "></activity> <activity android:name=". Optionview "android:screenorientation=" Portrait "></activity> </application> <uses-sdk and
roid: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, it will call the onconfigurationchanged (Configuration newconfig) Hook method. For example:
if (newconfig.orientation==configuration.orientation_landscape) {
//transverse
Setcontentview (r.layout.file_list _landscape);
} else{
//Vertical
Setcontentview (r.layout.file_list);
}
In the emulator, you can use the shortcut key F12 or ctrl+f11 to toggle the program's turn screen. Of course, when you start the simulator with the command line, you can use the parameter Emulator.exe-skin hvga-l to start the horizontal screen program directly.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.