android 横屏竖屏处理--禁止横屏
如果要定死横屏或者竖屏,不让它在用户旋转屏幕时改变:就用screenOrientation
<activity android:name=".MyActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
如果要做相应处理,就配置android:configChanges
For example, the following manifest code declares an activity that handles both the screen orientation change and keyboard availability change:
<activity android:name=".MyActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name">
Now, when one of these configurations change, MyActivity
does not restart. Instead, the MyActivity
receives a call to onConfigurationChanged()
. This method is passed a Configuration
object that specifies the new device configuration. By reading fields in the Configuration
, you can determine the new configuration and make appropriate changes by updating the resources used in your interface. At the time this method is called, your activity's Resources
object is updated to return resources based on the new configuration, so you can easily reset elements of your UI without the system restarting your activity.
Caution: Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion
and targetSdkVersion
attributes), you must include the "screenSize"
value in addition to the "orientation"
value. That is, you must decalare android:configChanges="orientation|screenSize"
. However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).
注意在API level 13以上, 要加上screenSize