DragSortAdapter icon indicating copy to clipboard operation
DragSortAdapter copied to clipboard

List drag and scroll does weird things when the first visible item moves

Open vinc3m1 opened this issue 9 years ago • 3 comments

Not sure what the cause is, but I'm guessing it might actually be an issue with LinearLayoutManager

vinc3m1 avatar Dec 02 '14 02:12 vinc3m1

to comment these lines worked for me. // recyclerView.post(new Runnable() { // @Override public void run() { adapter.notifyItemMoved(fromPosition, toPosition); // } // });

flaquir4 avatar Jun 03 '15 14:06 flaquir4

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 avatar Aug 28 '15 12:08 MFlisar

MFlisar's fix works for me.

ericbutler avatar Nov 27 '15 18:11 ericbutler