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 程序中禁止屏幕旋转和重启Activity
原文网址:http://www.cnblogs.com/bluestorm/p/3665890.html 禁止屏幕随手机旋转变化 有时候我们希望让一个程序的界面始终保持在一个方向,不随手机方向旋转而变 ...
- 如何在 Android 程序中禁止屏幕旋转和重启Activity
禁止屏幕随手机旋转变化 有时候我们希望让一个程序的界面始终保持在一个方向,不随手机方向旋转而变化:在AndroidManifest.xml的每一个需要禁止转向的Activity配置中加入android ...
- Android 禁止屏幕旋转 & 旋转屏幕时保持Activity内容
Android 禁止屏幕旋转 & 旋转屏幕时保持Activity内容 1.在应用中固定屏幕方向. 在AndroidManifest.xml的activity中加入: ...
- Android 禁止屏幕旋转、避免转屏时重启Activity
一.禁止屏幕旋转 在AndroidManifest.xml的每一个需要禁止转向的Activity配置中加入android:screenOrientation属性: 可选项: landscape = 横 ...
- Qt for Android 程序禁止屏幕旋转
有时候我们希望让一个程序的界面始终保持在一个方向,不随手机(平板)方向旋转而变化:在AndroidManifest.xml的每一个需要禁止转向的Activity配置中加入 android:screen ...
- 禁止屏幕旋转并同时解决以至于导致Activity重启的方法
1.禁止屏幕旋转在AndroidManifest.xml的每一个需要禁止转向的Activity配置中加入android:screenOrientation属性. //landscape(横向)port ...
- ionic2/3 禁止屏幕旋转,禁止横屏,竖屏
ionic2/ionic3禁止屏幕旋转,及解除禁止旋转 1.添加插件: cmd到项目目录---> cordova plugin add cordova-plugin-screen-orienta ...
- ios6和ios7禁止屏幕旋转
ios6和ios7禁止屏幕旋转 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOr ...
- 【Android】11.3 屏幕旋转和场景变换过程中GridView的呈现
分类:C#.Android.VS2015: 创建日期:2016-02-21 一.简介 实际上,对于布局文件中的View来说,大多数情况下,Android都会自动保存这些状态,并不需要我们都去处理它.这 ...
随机推荐
- JQuery中根据属性或属性值获得元素(6种情况获取方法)
根据属性获得元素 1.比如要获取页面p标签中属性有id的元素 $("p[id]").css("color","red"); 根据属性值获得元 ...
- Wannafly挑战赛2
Cut 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536K64bit IO Format: %lld 题目描述 给你一个长度为n的序列,你每次可以将一个序 ...
- PDO PDO_MYSQL MYSQLI MYSQL 的区别
MYSQL,MYSQLI 这两个扩展本身就是访问MYSQL数据库的驱动 PDO则是一个抽象层接口 向程序员提供可调用的API是由,MYSQL驱动.MYSQLI驱动,以及PDO来提供. PDO_MYSQ ...
- CMMI5
了解CMMI5是什么? 这种解决问题的思想很有用.
- docker 容器详解
Docker 是一个开源的应用容器引擎,基于Go语言 并遵Apache2.0协议开源,也是一种虚拟化技术.让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后发布到任何流行的 Linux ...
- matlab 中的删除文件
Matlab中有两种删除文件的方式: 一种是删除文件 delete()函数 //可以使用help delete命令查询delete()函数的使用方法 delete('p1.jpg' ...
- [USACO13JAN] Cow Lineup (单调队列,尺取法)
题目链接 Solution 尺取法板子,算是复习一波. 题中说最多删除 \(k\) 种,那么其实就是找一个颜色种类最多为 \(k+1\) 的区间; 统计一下其中最多的颜色出现次数. 然后直接尺取法,然 ...
- bzoj 3924 幻想乡战略游戏
题目大意: 有边权点权的树,动态修改点权 每次修改后求带权重心x (\(minimize\) \(S=\sum_i val[i]*dist[x][i]\)) 分析: 从暴力找突破口: 对于边x,y,设 ...
- poj Pseudoprime numbers 3641
Pseudoprime numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10903 Accepted: 4 ...
- 编写webconfig连接串与使用(新)
原文发布时间为:2008-07-27 -- 来源于本人的百度文章 [由搬家工具导入] webconfig 中<appSettings/> 得后面代码添加如下: <appSetting ...