Android 设定横屏,禁止屏幕旋转,Activity重置 [更新视频播放器相关]
Posted cxchanpin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 设定横屏,禁止屏幕旋转,Activity重置 [更新视频播放器相关]相关的知识,希望对你有一定的参考价值。
1. 设定屏幕方向
当指定了屏幕的方向后(非SCREEN_ORIENTATION_UNSPECIFIED),屏幕就不会自己主动的旋转了
有2中方式控制屏幕方向:
1.1 改动androidManifest.xml
1.2 setRequestedOrientation
横屏:
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. |
2. 禁止 屏幕旋转后重置Activity
屏幕旋转后会强制调用Activity.onCreate方法,所以会重置Activity
禁止方法:
改动AndroidManifest.xml
android:configChanges=”orientation”
近期在做Android的播放器。遇到採用以上方法后,仍然出现屏幕旋转后触发Activity.onCreate,经查阅资料后,发现须要加入screenSize处理
详细代码为:
android:configChanges="orientation|keyboardHidden|screenSize"
禁止重置Activity会造成Screen的宽高颠倒, 须要手动修正。
以上是关于Android 设定横屏,禁止屏幕旋转,Activity重置 [更新视频播放器相关]的主要内容,如果未能解决你的问题,请参考以下文章
我想知道怎么让android一直保持横屏状态不要一打开应用后又切换到竖屏如果是关闭设置里面的自动旋转屏幕之