No screen rotation changes with phone
Sometimes we want to keep the interface of a program in one direction and not rotate with the phone:
android:screenorientation= "Landscape" attribute is added to each activity configuration in Androidmanifest.xml that requires no steering.
Landscape = Landscape
Portrait = Portrait
Avoid restarting activity when you turn the screen
The activity is restarted every time the screen orientation is switched on Android, so you should save the current active state before the activity is destroyed and load the configuration when the activity is re-create, so that the in-progress game will not restart automatically!
To avoid restarting the activity when you turn the screen, you can redefine the direction in the Androidmanifest.xml file by adding android:configchanges= " Keyboardhidden|orientation " property).
Override the onconfigurationchanged (Configuration newconfig) method in the activity where you want to control the display direction of the screen so that the activity does not restart when you turn the screen.
@Overridepublic void onconfigurationchanged (Configuration newconfig) { super.onconfigurationchanged (newconfig) ; if (newconfig.orientation==configuration.orientation_landscape) { //transverse Setcontentview (r.layout.file_list _landscape); } else { //Vertical Setcontentview (r.layout.file_list); }}
<activity android:name= "com.myapp.MyActivity" android:label= "@string/app_name" android: screenorientation= "Landscape" android:configchanges= "keyboardhidden|orientation" > < intent-filter> <action android:name= "Android.intent.action.VIEW"/> <category android:name= "Android.intent.category.DEFAULT"/> </intent-filter></activity>
in the simulator you can do screen rotation by CTL+F11 simulation.
Welcome to AC http://blog.csdn.net/ycwol/article/details/46851273
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Disable screen rotation and restart activity in Android programs