I am using a RecyclerView with a Horizontal LinearLayoutManager.
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL,false));
For the adapter items to snap at the center, I've attached a LinearSnapHelper to the recyclerview.
SnapHelper helper = new LinearSnapHelper();
helper.attachToRecyclerView(recyclerView);
Now, I have two scenarios where I would want an item to come to center
- When my activity launches, it should launch with a specific item snapped to center.
- On tapping on an item in the recyclerview, it should get centered. For this, I've overridden the OnClick method in adapter's ViewHolder.
For both scenarios, I'm using
recyclerView.smoothScrollToPosition(position);
and the item gets centered. This however happens with a bouncy animation where a little extra scroll happens first and post that the item bounces back.
How can I disable this bouncy animation to get a smooth scroll?
Things I've tried - Used below APIs in place of smoothScrollToPosition
- LinearLayoutManager.scrollToPosition()
- LinearLayoutManager.scrollToPositionWithOffset()
Both the above APIs don't give a smooth scroll, plus the item doesn't get centered properly (since it's difficult to figure out the correct offset value for items that are not yet created/recycled back during the API call)
I couldn't find any method to disable/override animations in RecyclerView's Documentation. Could someone please help..