1. 设定屏幕方向

当指定了屏幕的方向后(非SCREEN_ORIENTATION_UNSPECIFIED),屏幕就不会自己主动的旋转了

有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

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的宽高颠倒, 须要手动修正。

最新文章

  1. Scrum Meeting 20161209
  2. 基于HTML5的WebGL结合Box2DJS物理应用
  3. 单点登录(SSO)系统的总结
  4. sqlite建表语句(特别是外键问题)
  5. TortoiseSVN常用批处理命令 分类: C# 2014-08-09 11:31 648人阅读 评论(1) 收藏
  6. J2EE用户CPU占用过大后的分析过程
  7. cocos2d-x + Lua接入iOS原生SDK的实现方案[转]
  8. Java基础之读文件——使用通道读二进制数据(ReadPrimes)
  9. Windows编写bat执行文件
  10. 【 POJ - 3801】Crazy Circuits(有源汇、上下界最小流)
  11. PhoneGap应用开发的那些坑爹事儿
  12. Masters of Doom
  13. SQL调优日志--内存问题
  14. mysqldump 使用说明
  15. Android项目中的各个模块框架设计
  16. TCP的定时器系列 — 保活定时器
  17. 关于UITabBarController的设置(iOS 开发)
  18. 20155219 2016-2017-2 《Java程序设计》第6周学习总结
  19. DROP TABLE 恢复【一】
  20. 启用PAE后虚拟地址到物理地址的转换

热门文章

  1. luogu3388 【模板】割点(割顶)
  2. 浮动 float
  3. maven项目打包jar,含有依赖jar
  4. 实现chrome多用户独立cookie
  5. iOS学习笔记26-视频播放
  6. [luoguP1963] [NOI2009]变换序列(二分图最大匹配)
  7. 洛谷P3327 [SDOI2015]约数个数和 【莫比乌斯反演】
  8. 关于在IE下面promise兼容的解决办法
  9. element-ui 的input组件 @keyup.enter事件的添加办法
  10. Best Coder Lotus and Characters