地址:http://blog.csdn.net/u011181236/article/details/52062568
1.有个需要注意的地方
@Override
public boolean onItemMove(int fromPosition, int toPosition) {
if (fromPosition == activityList.size() - 1 || toPosition == activityList.size() - 1) {
return false;
}
//此方法是2个元素的位置交换, 结合notifyItemMoved()的动画效果并不合理
// Collections.swap(activityList, fromPosition, toPosition);
listSwap(fromPosition, toPosition);
notifyItemMoved(fromPosition, toPosition);
return true;
}
private void listSwap(int from, int to) {
if (from < to) {
//用户手指触摸的位置在目标位置之前
activityList.add(to + 1, activityList.get(from));
activityList.remove(from);
} else {
//用户手指触摸的位置在目标位置之后
activityList.add(to, activityList.get(from));
activityList.remove(from + 1);
}
}