Android 11 Launcher3旋转Hotseat显示在底部

Launcher3

旋转屏幕之后,hotseat在左边或者右边,而不是下方。
Google设计如此,这样可以在横屏时workspace拥有更大的展示空间。

1、如果想HotSeat展示在下方,会导致workspace空间被压缩,图标比较拥挤。

配置如下:

<bool name="hotseat_transpose_layout_with_orientation">true</bool>

	/**
     * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
     * When {@code false}, either device is in portrait mode or the device is in landscape mode and
     * the hotseat is on the bottom row.
     */
    public boolean isVerticalBarLayout() {
        return isLandscape && transposeLayoutWithOrientation;
    }
2、横屏时workspace被压缩空间,allapps界面也被压缩空间。

原生设计:workspace和allapps界面图标大小、文字大小、间隔大小完全一致。
workspace因为横屏高度不够,拥挤我们无法解决。
但是allapps界面本身就是可以上下滚动的界面,我们可以稍微优化垂直方向的高度

显示的主要逻辑在InvariantDeviceProfileDeviceProfile中:

//固定的设备配置文件,内容读取来自device_profiles中的配置
//图标大小、文字大小、桌面行列号、文件夹行列号、allapps行列号、底边栏图标个数
packages/apps/Launcher3/src/com/android/launcher3/InvariantDeviceProfile.java
//device_profiles文件内容如下:
<profiles xmlns:launcher="http://schemas.android.com/apk/res-auto" >
    <grid-option
        launcher:name="6_by_5"
        launcher:numRows="5"
        launcher:numColumns="6"
        launcher:numFolderRows="4"
        launcher:numFolderColumns="4"
        launcher:numHotseatIcons="7"
        launcher:dbFile="launcher.db"
        launcher:defaultLayoutId="@xml/default_workspace_5x5" >
        <display-option
            launcher:name="Large Phone"
            launcher:minWidthDps="406"
            launcher:minHeightDps="694"
            launcher:iconImageSize="52"
            launcher:iconTextSize="13"
            launcher:canBeDefault="true" />
    </grid-option>
</profiles>
//设备配置文件,包含launcher实际显示的所有距离、大小、属性、等等
//根据设备可显示宽高、行列号、图标大小、文字大小进行适配,如果配置超出屏幕高度会进行缩放。
packages/apps/Launcher3/src/com/android/launcher3/DeviceProfile.java

//allapps界面格子高度
//launcher启动后,打断点,切换横竖屏,不会走这里
//因为InvariantDeviceProfile中有2个DeviceProfile变量,分别代表横竖屏状态的显示配置
//切换横竖屏不会重新走DeviceProfile的初始化,只需要切换到对应的DeviceProfile显示即可。
allAppsCellHeightPx = getCellSize().y;

//优化后计算方式如下:
//因为是横屏,availableWidthPx > availableHeightPx
//这里使用可用宽高的最大值进行计算,结果就会和竖屏时的allapps界面格子高度一致
Point result = new Point();
Point padding = getTotalWorkspacePadding();
result.y = calculateCellHeight(Math.max(availableWidthPx,availableHeightPx) - padding.y - cellLayoutBottomPaddingPx, inv.numRows);
allAppsCellHeightPx = result.y;
3、切换横竖屏

packages/apps/Launcher3/src/com/android/launcher3/Launcher.java

private void onIdpChanged(InvariantDeviceProfile idp) {
	//这里只贴了桌面配置相关的代码
	initDeviceProfile(idp);
}

private void initDeviceProfile(InvariantDeviceProfile idp) {
    // Load configuration-specific DeviceProfile
    mDeviceProfile = idp.getDeviceProfile(this);//正常切换横竖屏获取显示配置
    if (isInMultiWindowMode()) {//分屏模式显示配置初始化
        mDeviceProfile = mDeviceProfile.getMultiWindowProfile(
            this, getMultiWindowDisplaySize());
    }
    onDeviceProfileInitiated();
    mModelWriter = mModel.getWriter(getDeviceProfile().isVerticalBarLayout(), true);
}
//这里就是上面2 中说到的,根据横竖屏返回不同的显示配置,没有重新初始化。
public DeviceProfile getDeviceProfile(Context context) {
	return context.getResources().getConfiguration().orientation
		== Configuration.ORIENTATION_LANDSCAPE ? landscapeProfile : portraitProfile;
}
  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值