Android8 Launcher3 桌面应用行列数修改

Launcher3控制桌面(WorkSpace)应用图标的行列数其实核心来自于InvariantDeviceProfile类,这个类初始化了Launcher3的许多参数。

根据它的成员可以看到它至少控制了Launcher3的如下参数

/** * Number of icons per row and column in the workspace. 在WorkSpace中行列图标数量 */
public int numRows;
public int numColumns;

/** * Number of icons per row and column in the folder. 文件夹中图标行列数 */
public int numFolderRows;
public int numFolderColumns;
public float iconSize;
public float landscapeIconSize;
public int iconBitmapSize;
public int fillResIconDpi;
public float iconTextSize;

/** * Number of icons inside the hotseat area. Hotseat图标数量 */
public int numHotseatIcons;

其流程大体如下:

Launcher LauncherAppState InvariantDeviceProfile OnCreat() LauncherAppState.getInstance(this.context) getInstance() new LauncherAppState(context) LauncherAppState() new InvariantDeviceProfile(context) InvariantDeviceProfile() 通过Utilities.dpiFromPx 计算最小宽高Dps getPredefinedDeviceProfiles加载R.xml.device_profiles中预定义的Profile文件 findClosestDeviceProfiles计算最接近描述的DeviceProfiles(Array 排序) 使用排序后第一位(最接近)的作为参数 InvariantDeviceProfile Obj LauncherAppState Instance Obj Launcher LauncherAppState InvariantDeviceProfile

可以看到,默认的行列数初始化是在InvariantDeviceProfile类中处理的,而且其默认参数是通过计算设备宽高,并且与device_profiles.xml文件中取宽高最接近的一项来应用。
修改Workspace应用的行列数很容易,从上面整个通路里有多个地方都可以做到,但这里为了统一,还是直接修改device_profiles.xml预定义的选项即可。
要了解当前设备匹配的是哪一项,可以通过打Log获取:

// File: src\com\android\launcher3\InvariantDeviceProfile.java
public InvariantDeviceProfile(Context context){
    /....
    InvariantDeviceProfile closestProfile = closestProfiles.get(0);
    Log.d("GCAT DBG", "InvariantDeviceProfile: " + closestProfile.name);
    numRows = closestProfile.numRows;
    //.....
}

然后修改xml文件中的对应的Profile的参数即完成修改,当然你也可以将Profile中的参数删的只剩下一个,这样不管是什么分辨率和DPI都只会应用一个,也可以按照实际需求适配不同的DPI和屏幕分辨率:

// File: res\xml\device_profiles.xml
<?xml version="1.0" encoding="utf-8"?>
<profile
    launcher:name="Nexus 10_mod"
    launcher:minWidthDps="727"
    launcher:minHeightDps="1207"
    launcher:numRows="5"             //行数
    launcher:numColumns="7"          //列数
    launcher:numFolderRows="4"       //文件夹内行数
    launcher:numFolderColumns="5"    //文件夹内列数
    launcher:iconSize="76"           //Icon大小
    launcher:iconTextSize="14.4"     //提示文本大小
    launcher:numHotseatIcons="7"     //Hotseat图标数量
    launcher:defaultLayoutId="@xml/default_workspace_5x6"     //默认workspace布局文件,此处可同时修改默认存在hotseat或桌面的应用
    />

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值