失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > android activity 旋转 Android 设定横屏 禁止屏幕旋转 Activity重置

android activity 旋转 Android 设定横屏 禁止屏幕旋转 Activity重置

时间:2024-06-21 15:54:18

相关推荐

android activity 旋转 Android 设定横屏 禁止屏幕旋转 Activity重置

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重置》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。