andras
andras

Reputation: 3645

Recyclerview scrollToPosition() does not match findFirstVisibleItemPosition()

Basically what the title says. I am trying to implement my own fastscroller.

recyclerView.scrollToPosition(position);

System.out.println(position + " :: " + 
linearLayoutManager.findFirstVisibleItemPosition() );

Now the problem is that these two values do not match sometimes and I do not know why. This means, that the recyclerview does not scroll to the desired position and linearLayoutManager is correct about the current position.

The outputs are strange, the first visible position either matches the desired scroll position or the first visible position is below exactly 7 positions further than desired. (Except when recyclerview needs some time scroll to the position.)

Outputs:

I/System.out: 49 :: 42
I/System.out: 82 :: 42
I/System.out: 82 :: 75
...
I/System.out: 386 :: 379
I/System.out: 431 :: 379
I/System.out: 431 :: 424
I/System.out: 431 :: 424

So how can I scroll exactly to the desired position?

Edit: I realized I do not need to scroll recyclerview, but the LinearLayoutManager...

linearLayoutManager.scrollToPositionWithOffset(position, 0);

Upvotes: 0

Views: 649

Answers (1)

matt.mic
matt.mic

Reputation: 185

afaik the recyclerview scrolls as far as the desired position shows up at the bottom of the screen. llm.findFirstVisiblePosition() shows the first item on the screen == the one on the top of the screen.

Upvotes: 1

Related Questions