自动对齐优化
优化前:先删除后再添加,动画直接使用位移动画,数据可能存在异常
mWorkspace.removeWorkspaceItem(view);
int endX = vacantOut[0];
int endY = vacantOut[1];
View newView = view;
if(info instanceof ShortcutInfo) {
newView = createShortcut(info);
}
mWorkspace.moveViewToCell(newView, new int[]{startX, startY}, vacantOut);
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) newView.getLayoutParams();
lp.cellX = lp.tmpCellX = vacantOut[0];
lp.cellY = lp.tmpCellY = vacantOut[1];
info.cellX = vacantOut[0];
info.cellY = vacantOut[1];
getModelWriter().updateItemInDatabase(info);
mWorkspace.addInScreen(newView, info);
优化后:使用源生的方法,无需进行删除,数据更新一步完成
cellLayout.setUseTempCoords(false);
cellLayout.animateChildToPosition(cellLayout.getChildAt(info.cellX, info.cellY), endX, endY, 200,
0, true, true);
getModelWriter().addOrMoveItemInDatabase(info,
LauncherSettings.Favorites.CONTAINER_DESKTOP, info.screenId, endX, endY);