Skip to content
This repository has been archived by the owner on May 9, 2021. It is now read-only.

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

Open
vinc3m1 opened this issue Dec 2, 2014 · 3 comments

Comments

@vinc3m1
Copy link
Owner

vinc3m1 commented Dec 2, 2014

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

@vinc3m1 vinc3m1 changed the title Don't scroll when swapping with first element in linear list List drag and scroll does weird things when the first visible item moves Jan 16, 2015
@flaquir4
Copy link

flaquir4 commented Jun 3, 2015

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

@MFlisar
Copy link

MFlisar commented Aug 28, 2015

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
}

@ericbutler
Copy link

MFlisar's fix works for me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants