问题效果图:
从上图中可以清楚的看到,垂直方向上面的图标的间距是比较大的,所以按照这个问题我的思路1是更改Workspace空间的高度,这样图标之间垂直方向的间距就会减小,这是因为这是一个6*5的布局,减小Workspace的高度,仍然是6*5的布局,这样就会减小垂直方向图标的间距。但是我没有这么做,相反我有一个更加简单的思路2,那就是更改Workspace顶端和底端的内边距,这样也做到了垂直方向空间的压缩,是比较不错的,代码实现如下:
修改前代码:
@Override
public void setInsets(Rect insets) {
DeviceProfile grid = mLauncher.getDeviceProfile();
mWorkspaceFadeInAdjacentScreens = grid.shouldFadeAdjacentWorkspaceScreens();
Rect padding = grid.workspacePadding;
setPadding(padding.left, padding.top, padding.right, padding.bottom);
mInsets.set(insets);
if (mWorkspaceFadeInAdjacentScreens) {
// In landscape mode the page spacing is set to the default.
setPageSpacing(grid.edgeMarginPx);
} else {
// In portrait, we want the pages spaced such that there is no
// overhang of the previous / next page into the current page viewport.
// We assume symmetrical padding in portrait mode.
int maxInsets = Math.max(insets.left, insets.right);
int maxPadding = Math.max(grid.edgeMarginPx, padding.left + 1);
setPageSpacing(Math.max(maxInsets, maxPadding));
}
updateCellLayoutPadding();
updateWorkspaceWidgetsSizes();
setPageIndicatorInset();
}
修改后的代码:
@Override
public void setInsets(Rect insets) {
DeviceProfile grid = mLauncher.getDeviceProfile();
mWorkspaceFadeInAdjacentScreens = grid.shouldFadeAdjacentWorkspaceScreens();
Rect padding = grid.workspacePadding;
this.isLandscape = grid.isLandscape2;
if(isLandscape){
setPadding(padding.left, padding.top, padding.right, padding.bottom);
}else{
//setPadding(15, padding.top+120, 15, padding.bottom+100);
setPadding(padding.left, padding.top, padding.right, padding.bottom);
}
mInsets.set(insets);
if (mWorkspaceFadeInAdjacentScreens) {
// In landscape mode the page spacing is set to the default.
setPageSpacing(grid.edgeMarginPx);
} else {
// In portrait, we want the pages spaced such that there is no
// overhang of the previous / next page into the current page viewport.
// We assume symmetrical padding in portrait mode.
int maxInsets = Math.max(insets.left, insets.right);
int maxPadding = Math.max(grid.edgeMarginPx, padding.left + 1);
setPageSpacing(Math.max(maxInsets, maxPadding));
}
updateCellLayoutPadding();
updateWorkspaceWidgetsSizes();
setPageIndicatorInset();
}
修改后的效果图:
总结: