Android8.1 Launcher3 修改文件夹样式(一)
经过前面几天的努力,launcher看起来已经舒服多了;但是文件夹的外观还是让人不爽,不知道是不是因为美国人的审美跟我们不一样,还是Google工程师有意让我们自己修改。
这篇博客主要修改文件夹展开后的样式,博客理提到的文件夹都是展开后的文件夹。
1:首先让文件夹的大小固定
src/com/android/launcher3/folder/FolderPagedView.java -> FolderPagedView()
public FolderPagedView(Context context, AttributeSet attrs) {
super(context, attrs);
InvariantDeviceProfile profile = LauncherAppState.getIDP(context);
/* 修改最大行列 begin */
// mMaxCountX = profile.numFolderColumns;
// mMaxCountY = profile.numFolderRows;
mMaxCountX = 3;
mMaxCountY = 3;
/* 修改最大行列 0000009 end */
......
}
我这里就直接用固定数据代替了,其实应该用配置文件的。
再修改文件夹高度,我这里高度直接设置850:
src/com/android/launcher3/folder/Folder.java
private int getContentAreaHeight() {
/* 修改文件夹高度 begin */
// DeviceProfile grid = mLauncher.getDeviceProfile();
// int maxContentAreaHeight = grid.availableHeightPx
// - grid.getTotalWorkspacePadding().y - mFooterHeight;
// int height = Math.min(maxContentAreaHeight,
// mContent.getDesiredHeight());
// return Math.max(height, MIN_CONTENT_DIMEN);
return 850 - mFooterHeight;
/* 修改文件夹高度 end */
}
修改文件夹宽度
src/com/android/launcher3/folder/Folder.java
public int getDesiredWidth() {
/* 修改文件夹宽度 begin */
// return getPaddingLeft() + getPaddingRight() + (mCountX * mCellWidth);
return getPaddingLeft() + getPaddingRight() + (3 * mCellWidth);
/* 修改文件夹宽度 end */
}
运行一下,发现文件夹的大小是固定了,但是没有在屏幕中间显示,继续搞
2:让文件夹在屏幕中间显示
这一步我走了很多冤枉路,其实很简单,几行代码就搞定
src/com/android/launcher3/folder/Folder.java -> centerAboutIcon():