android如何改变系统默认横竖屏方向
获取屏幕的方向:
android.view.WindowManager manager = context.getSystemService(Context.WINDOW_SERVICE);
int rotation = manager.getDefaultDisplay().getRotation();
rotation的值为Surface.ROTATION_90或Surface.ROTATION_270时表示竖屏
rotation的值为Surface.ROTATION_0或者Surface.ROTATION_180表示横屏
如何改变Android默认的横竖屏,修改源码一个地方就可以了。
- public int rotationForOrientationLw(int orientation, int lastRotation,
- boolean displayEnabled) {
- if (mPortraitRotation < 0) {
- // Initialize the rotation angles for each orientation once.
- Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
- .getDefaultDisplay();
- if (d.getWidth() > d.getHeight()) {
- mPortraitRotation = Surface.ROTATION_90;
- mLandscapeRotation = Surface.ROTATION_0;
- mUpsideDownRotation = Surface.ROTATION_270;
- mSeascapeRotation = Surface.ROTATION_180;
- } else {
- mPortraitRotation = Surface.ROTATION_0;
- mLandscapeRotation = Surface.ROTATION_90;
- mUpsideDownRotation = Surface.ROTATION_180;
- mSeascapeRotation = Surface.ROTATION_270;
- }
- }
- {
- Log.i(TAG, "MediaPlayer.is not PlayingVideo");
- synchronized (mLock) {
- switch (orientation) {
- case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
- //always return portrait if orientation set to portrait
- //return mPortraitRotation;
- return mUpsideDownRotation;
- case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
- //always return landscape if orientation set to landscape
- return mLandscapeRotation;
- case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
- //always return portrait if orientation set to portrait
- //return mUpsideDownRotation;
- return mPortraitRotation;
- case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
- //always return seascape if orientation set to reverse landscape
- return mSeascapeRotation;
- case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
- //return either landscape rotation based on the sensor
- mOrientationListener.setAllow180Rotation(
- isLandscapeOrSeascape(Surface.ROTATION_180));
- return getCurrentLandscapeRotation(lastRotation);
- case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
- mOrientationListener.setAllow180Rotation(
- !isLandscapeOrSeascape(Surface.ROTATION_180));
- return getCurrentPortraitRotation(lastRotation);
- }
- mOrientationListener.setAllow180Rotation(
- orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
- || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
- // case for nosensor meaning ignore sensor and consider only lid
- // or orientation sensor disabled
- //or case.unspecified
- if (mLidOpen) {
- return mLidOpenRotation;
- } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) {
- return mCarDockRotation;
- } else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) {
- return mDeskDockRotation;
- } else {
- if (useSensorForOrientationLp(orientation)) {
- return mOrientationListener.getCurrentRotation(lastRotation);
- }
- return Surface.ROTATION_0;
- }
- }
- }
- }
修改上面倒数一行代码把return Surface.ROTATION_0改为你要的方向,记得这个要和上面的匹配,宽高不同,Surface.ROTATION_0也不同。因为代码开头就有
- if (mPortraitRotation < 0) {
- // Initialize the rotation angles for each orientation once.
- Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
- .getDefaultDisplay();
- if (d.getWidth() > d.getHeight()) {
- mPortraitRotation = Surface.ROTATION_90;
- mLandscapeRotation = Surface.ROTATION_0;
- mUpsideDownRotation = Surface.ROTATION_270;
- mSeascapeRotation = Surface.ROTATION_180;
- } else {
- mPortraitRotation = Surface.ROTATION_0;
- mLandscapeRotation = Surface.ROTATION_90;
- mUpsideDownRotation = Surface.ROTATION_180;
- mSeascapeRotation = Surface.ROTATION_270;
- }
- }
调试android记录 —— 屏幕改为竖屏
http://hi.baidu.com/jsxhxcq/item/960ca20607ed24e1359902d2
在调试android时,项目需要将屏幕竖屏,而且没有传感器。
按照网上的要求 在 build/target/product/core.mk 中
PRODUCT_POLICY := android.policy_phone //mid 改为phone
但是改完没有任何反应。随就追踪下去
1. 系统启动后 执行 performEnableScreen()
performEnableScreen() --> mPolicy.enableScreenAfterBoot();->
windowmanagerservice.Java
public void enableScreenAfterBoot() {
synchronized(mWindowMap) {
if (mSystemBooted) {
return;
}
mSystemBooted = true;
}
2. 在其函数中调用updateRotation();
public void enableScreenAfterBoot() {
readLidState();
updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
}
void updateRotation(int animFlags) {
mPowerManager.setKeyboardVisibility(mLidOpen);
int rotation = Surface.ROTATION_0;
if (mLidOpen) {
rotation = mLidOpenRotation;
} else if (mDockState == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) {
rotation = mCarDockRotation;
} else if (mDockState == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) {
rotation = mDeskDockRotation;
}
//if lid is closed orientation will be portrait
try {
//set orientation on WindowManager
mWindowManager.setRotation(rotation, true,
mFancyRotationAnimation | animFlags);
} catch (RemoteException e) {
// Ignore
}
}
3. setRotation()函数在 windowmanagerservices.java 中
static final boolean DEBUG_ORIENTATION = true; //打开调试信息
设置旋转函数, 下面调用关系
setRotation() - > setRotationUnchecked() - > setRotationUncheckedLocked()-> rotationForOrientationLw()
if (useSensorForOrientationLp(orientation)) {
// If the user has enabled auto rotation by default, do it.
int curRotation = mOrientationListener.getCurrentRotation();
return curRotation >= 0 ? curRotation : lastRotation;
}
让所有应用都横屏显示
http://blog.csdn.net/knock/article/details/7629585
- frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
- public int rotationForOrientationLw(int orientation, int lastRotation,
- boolean displayEnabled) {
- // Initialize the rotation angles for each orientation once.
- Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
- .getDefaultDisplay();
- if (d.getWidth() > d.getHeight()) {
- mPortraitRotation = Surface.ROTATION_0; //jeff. ROTATION_90;
- mLandscapeRotation = Surface.ROTATION_0;
- mUpsideDownRotation = Surface.ROTATION_90; //jeff. 270;
- mSeascapeRotation = Surface.ROTATION_180;
- }
android屏幕旋转在framework中的修改
http://blog.csdn.net/xulinguestc/article/details/6435957
在framework中修改,可以随意修改屏幕0°指向的方向,其实也是framework层做的映射。 修改HAL层来修改屏幕0°指向的方向应该也是可以的,还没有试过, 估计会复杂点,应该要修改触摸屏的坐标, 触摸键值映射表, 比较麻烦,其实没什么必要,修改framework层就可以搞定了。
平板电脑一般是默认横屏, 竖屏的APP程序, 会自动旋转90°, 由于是顺时针转90°, 需要改为逆时针转90°; 也就是要把portrait改逆时针转90°,这样就和手机一致,兼容很多gsensor游戏, 修改点如下:
- PhoneWindowManager.java(//192.168.1.4/opt/android_froyo_smdk/frameworks/policies/base/phone/com/android/internal/policy/impl)
- public int rotationForOrientationLw(int orientation, int lastRotation,
- boolean displayEnabled) {
- if (mPortraitRotation < 0) {
- // Initialize the rotation angles for each orientation once.
- Display d =((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
- .getDefaultDisplay();
- if (d.getWidth() > d.getHeight()) {
- mPortraitRotation = Surface.ROTATION_270;//Surface.ROTATION_90;
- mLandscapeRotation =Surface.ROTATION_0;
- } else {
- mPortraitRotation =Surface.ROTATION_0;
- mLandscapeRotation = Surface.ROTATION_270;//Surface.ROTATION_90;
- }
- }
以下是参考文章------------------------------------------------------------------------------------------------------
本行实现以后才发现,google在1.5到2.2这个过程中改进了很多,1.5修改竖屏比较麻烦,而2.2是相当的容易!
其实基本上google将之前版本的默认为竖屏的做法进行了改进,不需要再花费更多力气在屏幕的默认横竖切换上面。1.还是kernel竖屏,可以显示到屏幕出现"A N D R O I D"字样
启动参数里加入fbcon=rotate:1 (0:正常屏; 1:顺时钟转90度; 2:转180度; 3:顺时钟转270度;)
最后生成的autoconf.h里有类似项:
#define CONFIG_CMDLINE "console=ttySAC0,115200 fbcon=rotate:1"此项的解析在$(kernel)/drivers/video/console/fbcon.c
static int __init fb_console_setup(char *this_opt);
只是去初始化变量initial_rotation,然后initial_rotation会传递给其他需要的结构。
要选上:Device Drivers -> Graphics support -> Console display driver support ->Framebuffer Console support -> Framebuffer Console Rotation
注意:参考$(kernel)/documentation/fb/fbcon.txt2.android OS旋转屏幕
froyo中已经相当容易,仅修改一处:
frameworks/base/libs/surfaceflinger/SurfaceFlinger.cpp
void GraphicPlane::setDisplayHardware(DisplayHardware *hw)
{
mHw = hw; // initialize the display orientation transform.
// it's a constant that should come from the display driver.
// int displayOrientation = ISurfaceComposer::eOrientationDefault;
int displayOrientation = ISurfaceComposer::eOrientation90; //jeff.
。。。
}
或者只在init.rc中增加一项:
setprop ro.sf.hwrotation 90就这么简单的一修改,就可以全程竖屏显示了!
- 顶
- 0
- 踩
android如何改变系统默认横竖屏方向相关推荐
- android DrawerLayout 改变系统默认的灰色
在使用原生的侧滑栏的时候系统默认的主页显示是灰色的, 想要去掉这个灰色的颜色值 可以设置其颜色值为透明 假如定义 DrawerLayout drawerLayout 那么设置颜色透明的时候可以调用se ...
- android横竖屏切换动画,Android应用怎么实现屏幕横竖屏切换功能
Android应用怎么实现屏幕横竖屏切换功能 发布时间:2020-11-26 15:48:57 来源:亿速云 阅读:121 作者:Leah Android应用怎么实现屏幕横竖屏切换功能?针对这个问题, ...
- Android 12.0系统默认设置屏幕永不息屏
目录 1.概述 2. 系统默认设置屏幕永不休眠功能代码 3. 系统默认设置屏幕永不休眠功能分析和功能实现
- 全志H6 Android 7.0 平台 修改横竖屏显示
**问题描述:**全志H6 Android 7.0 并没有给出横竖屏显示属性的设置,可以自己设置一个persist.sys.rotation属性来控制横竖屏的显示 解决方案: diff --git a ...
- Android 10.0 设置默认息屏时间
1.概述 在10.0的系统产品定制化开发中,由于系统默认的息屏时间过短,所以要求修改默认息屏时间修改也是常见的修改功能, 在系统Settings中屏幕超时会根据默认息屏时间来显示屏幕超时的选项,然后设 ...
- Android设为系统默认的短信应用
要设为系统默认的短信应用首先要配置一下AndroidManifest.xml文件,添加下列: <!-- BroadcastReceiver that listens for incoming S ...
- Android App 手机兼容平板横竖屏切换
Android App兼容平板的开发.希望在手机上是竖屏显示,然后在平板上是横竖切换. /*** 判断是否平板设备* @param context* @return true:平板,false:手机* ...
- Android 10.0 系统默认开启wifi
1.概述 在10.0的系统产品中wifi是默认关闭的,由于的纯wifi的产品,所以需要要求默认打开wifi,开机后直接连wifi就可以了 所以需要找到相关的开关默认打开就可以了,然后开始连接wifi ...
- Swift iOS16 设置横竖屏方向
这里写一个兼容旧版ios的屏幕方向设置,实测了ios12.3 和 16.0.2是可以用的.做个笔记. 1.定义三个类型的屏幕模式设置. enum SCREEN_SET {case set_portca ...
最新文章
- 2021年大数据Flink(四十二):​​​​​​​BroadcastState
- python3中map函数_解决Python3下map函数的显示问题
- 深入理解Golang包导入
- 全志 更换Update升级路径 Patch
- 《地狱之刃:塞娜的献祭》如何通过人物情感营造恐怖氛围?
- 数学--矩阵快速幂详解
- C++ 学习之旅(5)——设置Setup文件目录
- Elasticsearch7.15.2 mysql8.0.26 logstash-input-jdbc 数据全量索引构建
- 在 CSS 中,width 和 height 指的是内容区域的宽度和高度
- 编写一个学生类 student,包含的属性有学号、姓名年龄,将所有学生存储在一个数组中
- java反射回调函数_java回调函数
- 曼大和华威计算机科学预科哪个好,华威预科申请曼彻斯特本科
- pandownload软件下载
- python代码编辑教程_python教程:pycharm编写代码的方式教学
- 红帽linux中文系统下载iso,红帽子9.0版下载-redhat linux 9.0 iso下载 简体中文正式版-IT猫扑网...
- ****怎么解决UBUNTU里面VIM编辑器键盘错乱问题****
- DASCTF X CBCTF 2022九月挑战赛 dino3d
- cadence软件初识
- Metasploitable2虚拟机镜像下载地址
- SparkStreaming面试题
热门文章
- linux中touch命令如何使用方法,Linux系统下touch命令的使用方法
- Spannable、Spanned、Editable用法及差别
- 微软亚洲工程院院长刘震:未来机器人的发展方向以及挑战
- java计算机毕业设计宠物店管理系统(附源码、数据库)
- OBS采集黑屏问题解决
- Three.js入门 (参考胖达老师)| 大帅老猿threejs特训
- 【libdatachannel】streamer与js客户端本机联调3 client流程
- 笔译现在用计算机考试了吗,做笔译需要计算机技术很强吗
- JMeter压力测试,五年Java开发者小米、阿里面经
- 2019-09-10 ~ 2022-01-12 第二段xx科技公司 工作生活总结