In Android to let a program's interface always keep a direction, do not follow the direction of the phone to change the way: As long as the androidmanifest.xml inside the configuration of a bit can be.
Add the android:screenorientation= "Landscape" attribute to the Androidmanifest.xml activity (activity to disable diversion) (Landscape is landscape, Portrait is portrait).
In addition, 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. To avoid restarting the activity when you turn the screen, you can redefine the direction in the Androidmanifest.xml file by adding android:configchanges= to each activity keyboardhidden| Orientation "property), and is controlled according to the activity's override onconfigurationchanged (Configuration Newconfig) method, which does not restart the activity at the time of the screen, but instead calls Onconfigurationchanged (Configuration newconfig) This method.
The sample code is as follows:
<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.liananse.ideal"Android:versioncode= "1"Android:versionname= "1.1" > <USES-SDKandroid:minsdkversion= "Ten" /> <ApplicationAndroid:icon= "@drawable/ic_launcher"Android:label= "@string/app_name" > <ActivityAndroid:label= "@string/app_name"Android:name= "Com.liananse.WelcomeActivity"android:screenorientation= "Portrait"android:configchanges= "Keyboardhidden|orientation"> <Intent-filter> <ActionAndroid:name= "Android.intent.action.MAIN" /> <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> </Intent-filter> </Activity> <ActivityAndroid:name= "Com.liananse.activity.MainActivity"android:screenorientation= "Portrait"android:configchanges= "Keyboardhidden|orientation"></Activity> <ActivityAndroid:name= "Com.liananse.activity.MusicActivity"android:screenorientation= "Portrait"android:configchanges= "Keyboardhidden|orientation"></Activity> <ActivityAndroid:name= "Com.liananse.activity.config.IdealAbout"Android:theme= "@android: Style/theme.notitlebar"android:screenorientation= "Portrait"android:configchanges= "Keyboardhidden|orientation"></Activity> <ActivityAndroid:name= "Com.liananse.activity.config.IdealSetting"Android:theme= "@android: Style/theme.notitlebar"android:screenorientation= "Portrait"android:configchanges= "Keyboardhidden|orientation"></Activity> <ActivityAndroid:name= "Net.youmi.android.AdActivity"android:configchanges= "Keyboard|keyboardhidden|orientation"android:screenorientation= "Portrait"/> <Meta-dataAndroid:name= "Youmi_channel"Android:value= "0" /> </Application> <uses-permissionAndroid:name= "Android.permission.INTERNET"/> <uses-permissionAndroid:name= "Android.permission.READ_PHONE_STATE"/> <uses-permissionAndroid:name= "Android.permission.ACCESS_NETWORK_STATE"/> <uses-permissionAndroid:name= "Android.permission.ACCESS_COARSE_LOCATION"/> <uses-permissionAndroid:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/></Manifest>
Prohibit Android horizontal screen vertical screen switch