Android 设定横屏,禁止屏幕旋转,Activity重置
来源:互联网 发布:java项目遇到最大困难 编辑:程序博客网 时间:2024/06/05 00:50
1. 设定屏幕方向
当指定了屏幕的方向后(非SCREEN_ORIENTATION_UNSPECIFIED),屏幕就不会自动的旋转了
有2中方式控制屏幕方向:
1.1 修改AndroidManifest.xml
1.2 setRequestedOrientation
横屏:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
竖屏:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
ActivityInfo:
int
SCREEN_ORIENTATION_BEHIND
Constant corresponding to behind in the screenOrientation attribute.
int
SCREEN_ORIENTATION_FULL_SENSOR
Constant corresponding to fullSensor in the screenOrientation attribute.
int
SCREEN_ORIENTATION_FULL_USER
Constant corresponding to fullUser in the screenOrientation attribute.
int
SCREEN_ORIENTATION_LANDSCAPE
Constant corresponding to landscape in the screenOrientation attribute.
int
SCREEN_ORIENTATION_LOCKED
Constant corresponding to locked in the screenOrientation attribute.
int
SCREEN_ORIENTATION_NOSENSOR
Constant corresponding to nosensor in the screenOrientation attribute.
int
SCREEN_ORIENTATION_PORTRAIT
Constant corresponding to portrait in the screenOrientation attribute.
int
SCREEN_ORIENTATION_REVERSE_LANDSCAPE
Constant corresponding to reverseLandscape in the screenOrientation attribute.
int
SCREEN_ORIENTATION_REVERSE_PORTRAIT
Constant corresponding to reversePortrait in the screenOrientation attribute.
int
SCREEN_ORIENTATION_SENSOR
Constant corresponding to sensor in the screenOrientation attribute.
int
SCREEN_ORIENTATION_SENSOR_LANDSCAPE
Constant corresponding to sensorLandscape in the screenOrientation attribute.
int
SCREEN_ORIENTATION_SENSOR_PORTRAIT
Constant corresponding to sensorPortrait in the screenOrientation attribute.
int
SCREEN_ORIENTATION_UNSPECIFIED
Constant corresponding to unspecified in the screenOrientation attribute.
int
SCREEN_ORIENTATION_USER
Constant corresponding to user in the screenOrientation attribute.
int
SCREEN_ORIENTATION_USER_LANDSCAPE
Constant corresponding to userLandscape in the screenOrientation attribute.
int
SCREEN_ORIENTATION_USER_PORTRAIT
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 设定横屏,禁止屏幕旋转,Activity重置
- Android 设定横屏,禁止屏幕旋转,Activity重置 [更新视频播放器相关]
- Android 设定横屏,禁止屏幕旋转,Activity重置 [更新视频播放器相关]
- Android 设定横竖屏,屏幕旋转导致Activity重置问题
- Android 旋转屏幕时禁止Activity重建
- Android 禁止屏幕旋转 & 旋转屏幕时保持Activity内容
- Android 禁止屏幕旋转 & 旋转屏幕时保持Activity内容
- Android 禁止屏幕旋转 & 旋转屏幕时保持Activity内容
- Android 禁止屏幕旋转 & 旋转屏幕时保持Activity内容
- Android禁止旋转屏幕
- Android 禁止屏幕旋转 & 屏幕旋转不刷新 Activity & 动态更改屏幕方向
- Android 4.0: 旋转屏幕时禁止Activity重新加载
- Android禁止屏幕旋转和重启Activity
- android 程序中禁止屏幕旋转和重启Activity
- Android:屏幕旋转时,禁止Activity重新加载
- ANDROID竖屏,屏幕旋转禁止重新加载activity
- Android禁止屏幕旋转,旋转屏幕时不重新加载当前activity
- 反素数 51Nod1060 最复杂的数
- 【React Native开发】React Native移植原生Android项目(Mac用)
- system V 消息队列的用法
- 单例模式
- 网站建设(4)——服务器的选择和购买
- Android 设定横屏,禁止屏幕旋转,Activity重置
- Java千百问_04异常处理(002)_java如何捕获异常
- Stanford 机器学习笔记 Week11 Application Example: Photo OCR
- VMware中CentOS设置静态IP
- 剑指offer-面试题10:二进制中1的个数
- 2010年山东省第一届ACM大学生程序设计竞赛:Balloons
- NSTimer 简述
- CodeForces 21 C Stripe 2
- Linux 下编译链接动静态库