6

I tried this code for drag and drop : https://github.com/iPaulPro/Android-ItemTouchHelper-Demo.

Here is a video : https://youtu.be/lMsv2jYpbi4

Is there a way to speed up the scrolling during drag-and-drop ?

jhegedus
  • 18,516
  • 11
  • 84
  • 147

1 Answers1

16

In your class that extends ItemTouchHelper.Callback, override the method:

@Override
public int interpolateOutOfBoundsScroll(RecyclerView recyclerView, int viewSize, int viewSizeOutOfBounds, int totalSize, long msSinceStartScroll) {
    final int direction = (int) Math.signum(viewSizeOutOfBounds);
    return 10 * direction;
}

This is a simple example which uses a fixed scroll speed, but if you wanted something that started slow and sped up (like the super.interpolateOutOfBoundsScroll does) you can do some maths based on the time since scrolling (msSinceStartScroll) and also the position in the overall scroll (example scroll faster when in the middle of the scroller and slower when you near the start/end).

Vladimir Vagaytsev
  • 2,650
  • 9
  • 31
  • 30
cwasyl
  • 161
  • 1
  • 6