2

I want to smoothscroll the recyclerview to a random place between two items after clicking a button. By using

smoothScrollBy(dx , dy)

I can get the right place but cant control the speed/duration(too fast,i hope to make it slow).

By using

smoothScrollToPosition()

and implementing calculateSpeedPerPixel() i can control the speed but cant got the right place (cant stop between two items).

in fact i am looking for a way to do the same work as

ListView.smoothScrollBy(int distance, int duration).

Is there a solution?

Atef Hares
  • 4,715
  • 3
  • 29
  • 61
Zerlings
  • 21
  • 3

2 Answers2

1

Mark Allison has a blog post series that explains how you can customise and control the duration when you want to scroll to a position.

https://blog.stylingandroid.com/scrolling-recyclerview-part-1/

Johan Paul
  • 2,203
  • 2
  • 22
  • 38
0

You should probably use this method with a custom interpolator: smoothScrollBy(int, int, Interpolator)

You can for example use an Accelerate Interpolator with a different value. Try varying the number to see what suits you:

smoothScrollBy(dx , dy, new AccelerateInterpolator(2));
gbaccetta
  • 4,449
  • 2
  • 20
  • 30
  • this method seems only change the animation but not the duration of scrolling . thank you all the same – Zerlings Feb 18 '17 at 03:08