0

I have a RecyclerView setup with a horizontal LinearLayoutManager that displays views in full page size (i.e. like a ViewPager would).

What I would like to achieve is to programmatically smooth scroll to a certain position. However not with a linear scroll like smoothScrollToPosition(int) does, but with an ease-in/ease-out effect instead.

I looked at RecyclerView.SmoothScroller but from what I could tell there is no way to implement this behaviour, because information about the total scroll distance/duration seems to be missing.

The next thing I tried was to use scrollTo(int, int) manually which seems to be unsupported in RecyclerView.

I have for now resorted to sending MotionEvents to simulate a drag on the recylcer view. But this feels very overkill for what should be a simple problem.

Is there another way to achieve my goal?

1 Answer 1

1

You can try with creating custom RecyclerView and overriding smoothScrollBy method:

public class CustomInterpolatorRecyclerView extends RecyclerView { @Override public void smoothScrollBy(int dx, int dy) { super.smoothScrollBy(dx, dy, new AccelerateDecelerateInterpolator()); //pass your more advanced ease-in/ease-out interpolator here } 
Sign up to request clarification or add additional context in comments.

1 Comment

Exactly what I was looking for.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.