Shikha Ratra Shikha Ratra - 12 days ago 7
Android Question

How to center the Clicked position in the Recyclerview

I want to center the clicked position in the

Recyclerview
. I am able to scroll the
Recyclerview
to certain position but i want to middle that position in the screen.
I used this method to scroll to that position.

videoRecyclerview.scrollToPosition(position);

Answer

if you use linearlayoutManager, you can use this code,

linearLayoutManager.scrollToPositionWithOffset(2, 20);

(linearLayoutManager.void scrollToPositionWithOffset (int position, 
            int offset))

Setting the offset to 0 should align with the top