当指定了屏幕的方向后(非SCREEN_ORIENTATION_UNSPECIFIED),屏幕就不会自动的旋转了
有2中方式控制屏幕方向:
横屏:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
竖屏:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
ActivityInfo:
int |
Constant corresponding to behind in the screenOrientation attribute. |
|
int |
Constant corresponding to fullSensor in the screenOrientation attribute. |
|
int |
Constant corresponding to fullUser in the screenOrientation attribute. |
|
int |
Constant corresponding to landscape in the screenOrientation attribute. |
|
int |
Constant corresponding to locked in the screenOrientation attribute. |
|
int |
Constant corresponding to nosensor in the screenOrientation attribute. |
|
int |
Constant corresponding to portrait in the screenOrientation attribute. |
|
int |
Constant corresponding to reverseLandscape in the screenOrientation attribute. |
|
int |
Constant corresponding to reversePortrait in the screenOrientation attribute. |
|
int |
Constant corresponding to sensor in the screenOrientation attribute. |
|
int |
Constant corresponding to sensorLandscape in the screenOrientation attribute. |
|
int |
Constant corresponding to sensorPortrait in the screenOrientation attribute. |
|
int |
Constant corresponding to unspecified in the screenOrientation attribute. |
|
int |
Constant corresponding to user in the screenOrientation attribute. |
|
int |
Constant corresponding to userLandscape in the screenOrientation attribute. |
|
int |
Constant corresponding to userPortrait in the screenOrientation attribute. |
屏幕旋转后会强制调用Activity.onCreate方法,所以会重置Activity
禁止方法:
修改AndroidManifest.xml
android:configChanges=”orientation”
Android 设定横屏,禁止屏幕旋转,Activity重置
原文地址:http://blog.csdn.net/matrix_laboratory/article/details/40045961