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

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

时间: 2024-08-02 11:04:52

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

【转】如何在 Android 程序中禁止屏幕旋转和重启Activity

原文网址:http://www.cnblogs.com/bluestorm/p/3665890.html 禁止屏幕随手机旋转变化 有时候我们希望让一个程序的界面始终保持在一个方向,不随手机方向旋转而变化:在AndroidManifest.xml的每一个需要禁止转向的Activity配置中加入android:screenOrientation=”landscape” 属性. landscape = 横向portrait = 纵向 避免在转屏时重启Activity android中每次屏幕方向切换时

android 程序中禁止屏幕旋转和重启Activity

禁止屏幕随手机旋转变化 有时候我们希望让一个程序的界面始终保持在一个方向,不随手机方向旋转而变化: 在AndroidManifest.xml的每一个需要禁止转向的Activity配置中加入android:screenOrientation="landscape" 属性. landscape = 横向 portrait = 纵向 避免在转屏时重启Activity android中每次屏幕方向切换时都会重启Activity,所以应该在Activity销毁前保存当前活动的状态,在Activi

Android 设定横屏,禁止屏幕旋转,Activity重置

1. 设定屏幕方向 当指定了屏幕的方向后(非SCREEN_ORIENTATION_UNSPECIFIED),屏幕就不会自动的旋转了 有2中方式控制屏幕方向: 1.1 修改AndroidManifest.xml 在AndroidManifest.xml的activity中加入: 横屏: android:screenOrientation="landscape" 竖屏: android:screenOrientation="portrait" 1.2 setReques

Qt for Android 程序禁止屏幕旋转

有时候我们希望让一个程序的界面始终保持在一个方向,不随手机(平板)方向旋转而变化:在AndroidManifest.xml的每一个需要禁止转向的Activity配置中加入 android:screenOrientation=”landscape” 属性. landscape = 横向 portrait = 纵向 原创文章,转载请注明: 转载自 http://www.mr-wu.cn/ 吴川斌的博客 本文链接地址: Qt for Android 程序禁止屏幕旋转 http://www.mr-wu.

ionic2/3 禁止屏幕旋转,禁止横屏,竖屏

ionic2/ionic3禁止屏幕旋转,及解除禁止旋转 1.添加插件: cmd到项目目录---> cordova plugin add cordova-plugin-screen-orientation 详情看https://github.com/apache/cordova-plugin-screen-orientation import { Component } from '@angular/core'; import { Platform } from 'ionic-angular';

ios6和ios7禁止屏幕旋转

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return (toInterfaceOrientation == UIInterfaceOrientationPortrait); } - (BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations

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

分类:C#.Android.VS2015: 创建日期:2016-02-21 一.简介 实际上,对于布局文件中的View来说,大多数情况下,Android都会自动保存这些状态,并不需要我们都去处理它.这一节仍以GridView为例(第10章已经介绍过其基本用法了),说明屏幕旋转以及场景切换过程中用GridView呈现的图像是如何自动变换的. 本节主要关注下面的问题: (1)如何通过GridView显示多幅图像. (2)如何使用Activity从一个活动切换到另一个活动,即利用Activity实现场

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

本文主要介绍Android ViewGroup/View的绘制流程,及常用的自定义ViewGroup的方法.在此基础上介绍动态控制View的位置的三种方法,并给出最佳的一种方法. 一.ViewGroup/View的绘制流程 简单的说一个View从无到有需要三个步骤,onMeasure.onLayout.onDraw,即测量大小.放置位置.绘制三个步骤.而ViewGroup的onMeasure.onLayout流程里,又会遍历每个孩子,并最终调到孩子的measure().layout()函数里.与

ios 手动控制开启、禁止屏幕旋转

最近在公司做iPad开发,跟大多数的iPhone应用不一样,iPad程序要求支持横竖屏,但有时候有的页面不需要屏幕旋转,上网搜了很多资料发现都是不可行或者不符合需求的.首先,直接在UIViewController重写父类以下几个方法,发现是不执行的. - (BOOL)shouldAutorotate; - (NSUInteger)supportedInterfaceOrientations; - (UIInterfaceOrientation)preferredInterfaceOrientat