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都会自动保存这些状态,并不需要我们都去处理它.这 ...
随机推荐
- 令人惊叹的sublime text 3 插件
1.ChineseLocalization------语言汉化.(新手必备) 2.SublimeTmpl------打开生成模板.(新手必备) 3.SublimeCodeIntel------代码自 ...
- javascript 获取键盘上的按键代码KeyCode
Enter键的keyCode为13 Alt + Enter 的keyCode为10 $(document).on( 'keypress', function ( e ) { console.log( ...
- 第1章jquery选择器
一.jquery等价于$ jquery选择器继承了css选择器的风格. $("#ID")代替了document.getElementById()函数,即通过id获取元素. $(&q ...
- Text Region Mask
本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/52886351 Python code ...
- 【bzoj4407】于神之怒加强版 莫比乌斯反演+线性筛
题目描述 给下N,M,K.求 输入 输入有多组数据,输入数据的第一行两个正整数T,K,代表有T组数据,K的意义如上所示,下面第二行到第T+1行,每行为两个正整数N,M,其意义如上式所示. 输出 如题 ...
- 【bzoj2476】战场的数目 矩阵乘法优化dp
题目描述 (战场定义为对于最高的一列向两边都严格不增的“用积木搭成”的图形) 输入 输入文件最多包含25组测试数据,每个数据仅包含一行,有一个整数p(1<=p<=109),表示战场的图形周 ...
- HDU——1020Encoding(水题,string过)
Encoding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- 《学习笔记》Maven
Maven优点之一:jar包统一管理+升级容易+项目清爽 试想一下,我们会在工作中同时创建很多项目,每个项目可能都会引用一些公用的jar包(.NET中是dll文件),一种作法是每个项目里,都复制一份这 ...
- Python Base One
//this is my first day to study python, in order to review, every day i will make notes (2016/7/31) ...
- bzoj3924 [Zjoi2015]幻想乡战略游戏 点分树,动态点分
[BZOJ3924][Zjoi2015]幻想乡战略游戏 Description 傲娇少女幽香正在玩一个非常有趣的战略类游戏,本来这个游戏的地图其实还不算太大,幽香还能管得过来,但是不知道为什么现在的网 ...