Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RecyclerView drag-drop - using ItemTouchHelper - How to set scrolling speed faster while dragging?

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 ?

like image 563
jhegedus Avatar asked Jul 29 '16 15:07

jhegedus


1 Answers

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).

like image 91
cwasyl Avatar answered Sep 21 '22 12:09

cwasyl