从android O开始,主界面的默认图标就是圆形的,所以文件夹图标默认显示的4个应用其实是按照圆弧排列的,之前有看到文章描述做成9宫格就可以很明显地看出来;
公司需求是默认用正方形布局,不管2个还是3个、4个应用都是用正方形布局排列
默认的布局会裁剪掉一部分,图标显示太大不美观,所以先调整下图标比例,下面记录下定制的重点
1、原生的版本是会根据文件夹内部应用数量调整缩放比例的,我们不需要这个,所以固定缩放比例
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.folder;
import android.graphics.drawable.Drawable;
/**
* Manages the parameters used to draw a Folder preview item.
*/
class PreviewItemDrawingParams {
float transX;
float transY;
float scale;
float overlayAlpha;
FolderPreviewItemAnim anim;
public boolean hidden;
Drawable drawable;
//文件夹内部应用图标缩略图的缩放比例
private final float DEFAULT_SCALE = 0.42f;
PreviewItemDrawingParams(float transX, float transY, float scale, float overlayAlpha) {
this.transX = transX;
this.transY = transY;
this.scale = DEFAULT_SCALE;//scale;
this.overlayAlpha = overlayAlpha;
}
public void update(float transX, float transY, float scale) {
// We ensure the update will not interfere with an animation on the layout params
// If the final values differ, we cancel the animation.
if (anim != null) {
if (anim.finalState[1] == transX || anim.finalState[2] == transY
|| anim.finalState[0] == scale) {
return;
}
anim.cancel();
}
this.transX = transX;
this.transY = transY;
this.scale = DEFAULT_SCALE;//scale;
}
}
。。。
com.android.launcher3.icons.IconNormalizer.java
private static final float MAX_SQUARE_AREA_FACTOR = 475.0f / 576; //375.0f / 576;
private static final float MAX_CIRCLE_AREA_FACTOR = 480.0f / 576; //380.0f / 576;
2、固定用4个应用的布局
com.android.launcher3.folder.ClippedFolderIconLayoutRule.java
private static final float MAX_RADIUS_DILATION = 0.01f;//0.15f;
private static final float ITEM_RADIUS_SCALE_FACTOR = 1.22f;//1.33f;
...
private void getPosition(int index, int curNumItems, float[] result) {
/
//modify by hwj20210904默认用4个应用的布局
curNumItems = Math.max(curNumItems, 4/*2*/);
......
result[0] = mAvailableSpace / 2 + (float) (radius * Math.cos(theta) / 2) - halfIconSize + 5/*矫正居中参数*/;
result[1] = mAvailableSpace / 2 + (float) (- radius * Math.sin(theta) / 2) - halfIconSize + 5;
}
3、调整文件夹的圆角
res里面的xml有个ford_shapes.xml的文件定义
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2019 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<shapes xmlns:launcher="http://schemas.android.com/apk/res-auto" >
<Circle launcher:folderIconRadius="9" />
<!-- Default icon for AOSP -->
<RoundedSquare launcher:folderIconRadius="0.5" />
<!-- Rounded icon from RRO -->
<RoundedSquare launcher:folderIconRadius="0.7" />
<!-- Square icon -->
<RoundedSquare launcher:folderIconRadius="0.5" />
<TearDrop launcher:folderIconRadius="0.7" />
<Squircle launcher:folderIconRadius="0.7" />
</shapes>