Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set item to center of RecyclerView when using scrollToPosition

I am using a RecyclerView to display items horizontally.

I want that when i use scrollToPosition(position), the respective item appears on the center not on the left.

Does anyone has any idea how to do it? I know how to do it using smoothScrollToPosition, but in this case i need to do it with scrollToPosition.

RecyclerView exemple

like image 414
hamid Avatar asked Apr 05 '17 07:04

hamid


1 Answers

Consider using scrollToPositionWithOffset(int position, int offset) and passing required offset as you wish from left. You can find your required offset by using the width of the parent layout (assuming you are using horizontal recycler view). cheers :)

like image 178
Darish Avatar answered Sep 19 '22 07:09

Darish