如果要定死横屏或者竖屏,不让它在用户旋转屏幕时改变:就用screenOrientation
如果要做相应处理,就配置android:configChanges
For example, the following manifest code declares an activity that handles both the screen orientation change and keyboard availability change:
Now, when one of these configurations change, MyActivity
does not restart. Instead, the MyActivity
receives a call to . This method is passed a
object that specifies the new device configuration. By reading fields in the
, 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
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 and 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