DragSortAdapter
DragSortAdapter copied to clipboard
List drag and scroll does weird things when the first visible item moves
Not sure what the cause is, but I'm guessing it might actually be an issue with LinearLayoutManager
to comment these lines worked for me. // recyclerView.post(new Runnable() { // @Override public void run() { adapter.notifyItemMoved(fromPosition, toPosition); // } // });
Should this already have been fixed?
There's a comment in the code like // fix for weird scrolling when animating first item
... But the current version does not work correctly.
For me, flaquir4's solution stops everything to work. of course, the adpater must be notified about the change...
EDIT
Following fixes the problem for me and is confirm to what the issue report suggests, call scrollToPosition(0)
AFTER notifyItemMoved
:
if (adapter.move(fromPosition, toPosition)) {
recyclerView.post(new Runnable() {
@Override public void run() {
adapter.notifyItemMoved(fromPosition, toPosition);
if (fromPosition == 0 || toPosition == 0)
recyclerView.scrollToPosition(0);
}
});
}
https://code.google.com/p/android/issues/detail?id=99047 }
MFlisar's fix works for me.