1. 设定屏幕方向
有2中方式控制屏幕方向:
1.1 修改AndroidManifest.xml
在AndroidManifest.xml的activity中加入:
横屏:
android:screenOrientation=”landscape”
竖屏:
android:screenOrientation=”portrait”
1.2 setRequestedOrientation
横屏:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
竖屏:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
ActivityInfo:
int
Constantcorrespondingtobehindinthe
int
ConstantcorrespondingtofullSensorinthe
int
ConstantcorrespondingtofullUserinthe
int
Constantcorrespondingtolandscapeinthe
int
Constantcorrespondingtolockedinthe
int
Constantcorrespondingtonosensorinthe
int
Constantcorrespondingtoportraitinthe
int
ConstantcorrespondingtoreverseLandscapeinthe
int
ConstantcorrespondingtoreversePortraitinthe
int
Constantcorrespondingtosensorinthe
int
ConstantcorrespondingtosensorLandscapeinthe
int
ConstantcorrespondingtosensorPortraitinthe
int
Constantcorrespondingtounspecifiedinthe
int
Constantcorrespondingtouserinthe
int
ConstantcorrespondingtouserLandscapeinthe
int
ConstantcorrespondingtouserPortraitinthe
2. 禁止屏幕旋转后重置Activity
屏幕旋转后会强制调用Activity.onCreate方法,所以会重置Activity
禁止方法:
修改AndroidManifest.xml
android:configChanges=”orientation”
原文:/matrix_laboratory/article/details/40045961
如果觉得《android activity 旋转 Android 设定横屏 禁止屏幕旋转 Activity重置》对你有帮助,请点赞、收藏,并留下你的观点哦!