framework层,屏幕旋转90度

本文详细解释了如何使用PhoneWindowManager.java中的rotationForOrientationLw方法控制Android设备屏幕旋转90度,包括设置mForceDefaultOrientation变量为true以适应特定屏幕尺寸,并通过配置文件或命令行进行调整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PhoneWindowManager.java的作用有很多,今天这里只讲一个,就是控制屏幕旋转90度

在这个类中有这个方法rotationForOrientationLw

if (mForceDefaultOrientation) {
            return Surface.ROTATION_90; //90,180,270 改变这里就可以实现屏幕的旋转
        }

要想从这个判断语句中进来,就需要将mForceDefaultOrientation的值设为true,在源码中前面有定义,初始值为false。

// Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
        // http://developer.android.com/guide/practices/screens_support.html#range
        mForceDefaultOrientation = true ;//longSizeDp >= 960 && shortSizeDp >= 720 &&
               // res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
                //For debug purposes the next line turns this feature off with:
                // $ adb shell setprop config.override_forced_orient true
                // $ adb shell wm size reset
              // !"true".equals(SystemProperties.get("config.override_forced_orient"));

可以在上出标绿的地方将默认值设为true。


修改之前,setInitialDisplaySize这个方法中,如下:

// Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
        // http://developer.android.com/guide/practices/screens_support.html#range
        mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
                res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
                //For debug purposes the next line turns this feature off with:
                // $ adb shell setprop config.override_forced_orient true
                // $ adb shell wm size reset
               !"true".equals(SystemProperties.get("config.override_forced_orient"));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值