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

Android 设定横屏,禁止屏幕旋转,Activity重置 [更新视频播放器相关]相关推荐

  1. android中用代码实现禁止页面旋转,Android通过代码禁止屏幕旋转

    最近在做一个组件,需要让Activity保持启动时的方向而不旋转,查询了网上的办法,大都是通过修改Manifest文件实现屏幕方向的设置,但是这样的方式无法实现我要的效果,即保持横屏或竖屏. 最后,通 ...

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

    1. 设定屏幕方向 有2中方式控制屏幕方向: 1.1 修改AndroidManifest.xml 在AndroidManifest.xml的activity中加入: 横屏: android:scree ...

  3. Android 禁止屏幕旋转

    Android 开发中禁止屏幕旋转 我们通常有两种方案 方案一 在AndroidManifest.xml 中设置activity 中的android:screenOrientation 属性值 方案二 ...

  4. Android 禁止屏幕旋转 旋转屏幕时保持Activity内容

    Android 禁止屏幕旋转 & 旋转屏幕时保持Activity内容 1.在应用中固定屏幕方向. 在AndroidManifest.xml的activity中加入:            an ...

  5. Android开发实践:屏幕旋转的处理

    最近开发Android Camera相关的程序,被屏幕旋转搞得头大,一方面得考虑屏幕旋转后布局的变化,另一方面得搞清楚屏幕的旋转方向.角度与Camera的Preview角度的关系.本来通过重载Acti ...

  6. android 屏幕方向监听,Android如何监听屏幕旋转

    背景 关于个人,前段时间由于业务太忙,所以一直没有来得及思考并且沉淀点东西:同时组内一个个都在业务上能有自己的思考和总结,在这样的氛围下,不由自主的驱使周末开始写点东西,希望自己除了日常忙于业务,可以 ...

  7. 【Android】11.3 屏幕旋转和场景变换过程中GridView的呈现

    分类:C#.Android.VS2015: 创建日期:2016-02-21 一.简介 实际上,对于布局文件中的View来说,大多数情况下,Android都会自动保存这些状态,并不需要我们都去处理它.这 ...

  8. 让Android控件随着屏幕旋转自由转移至任何地方(附demo)

    本文主要介绍Android ViewGroup/View的绘制流程,及常用的自定义ViewGroup的方法.在此基础上介绍动态控制View的位置的三种方法,并给出最佳的一种方法. 一.ViewGrou ...

  9. 让Android控件随着屏幕旋转自由转移至任何地方 附demo

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 本文主要 ...

最新文章

  1. django基础知识~RBAC实验部分代码记录
  2. nginx 静态资源WEB服务
  3. js 时间戳转换成时间_JavaScript 时间戳转成日期格式
  4. 关于Python3.6下登陆接口的尝试
  5. sysadmin默认密码_从sysadmin过渡到DevOps工程师的案例
  6. 计算机多媒体发展2018,2018秋季学期计算机多媒体项目圆满结课
  7. 理想汽车市值逼近蔚来,王兴曾多次在饭否为其站台
  8. .Net中的RealProxy实现AOP
  9. wow.js中各种特效对应的类名
  10. vue视频教程大全下载
  11. Linux dstat监控工具简讲
  12. linux系统富士通打印机驱动,PRIMERGY:驱动下载 - 富士通中国
  13. 【NLP】第13章 用Transformers分析假新闻
  14. 如何查看ios sdk版本
  15. 两台笔记本通过蓝牙传输文件
  16. Revit二次开发之族库管理系统
  17. scikit-learn源码学习之cluster.MeanShift
  18. PHP超简洁小猫咪图床源码
  19. Home Assistant初学者指南 -1之 Home Assistant安装
  20. python中对象的定义_python中对象的定义和使用

热门文章

  1. Spring、Spring Boot和TestNG测试指南 - 测试关系型数据库
  2. 理解 JavaScript 作用域和作用域链
  3. 速读《构建之法:现代软件工程》提问
  4. **php队列的实现思路和详细过程
  5. 安卓完全退出程序的六种方法(欢迎新手学习,大手指导)
  6. 1.5 Activity08 RadioButton
  7. SmartNIC/DPU — 基本组成示例
  8. 5G 信令流程 — UE 状态机
  9. Keil进入仿真,窗口不显示程序运行箭头
  10. React Native 与 嵌入Android原生与Activity页面互相跳转