0

I'm trying to programatically scroll to an item in my RecyclerView based on position.

The following code works when scrolling to an item in the RecyclerView adapters data if the position is visible on screen / rendered:

recyclerView.getLayoutManager()).scrollToPositionWithOffset(position, 0);

However if I set a position to a value which is not yet visible on the screen / rendered, the page is only scrolled just below the last item which is visible / already rendered. E.g. it works for the first 4 items which are visible, but not the 4 which are off screen.

For extra details the data in the adapter is set in an onSuccess callback:

// update the data in the adapter after hitting a REST API
adapter.updateItems(data);
adapter.notifyDataSetChanged();

// then I scroll to the position
recyclerView.getLayoutManager()).scrollToPositionWithOffset(position, 0);

Other methods to invoke the scrolling haven't worked - e.g. just calling recyclerView.scrollToPosition(position)

And the view is rendered inside a BottomSheetDialog.

There seem to be quite a few questions relating to similar things which have not solved my problems - eg RecyclerView - How to smooth scroll to top of item on a certain position?

UPDATE

Actually trying it with a different longer data set its not only the fact that the item position is not visible - it appears to only be the last items which don't scroll correctly (e.g the last three).

Thanks!

dannymilsom
  • 2,386
  • 1
  • 18
  • 19
  • Its probably not scrolling to it because it has not been rendered yet. Is there a way for you to wait for it to fully render? – ShaneG Nov 29 '17 at 17:12
  • Yep I thought so - but other questions suggest you can scroll to the end just fine. I've actually updated the question as more specifically its just the last few items which break scrolling (having expanded the data set I can scroll to other positions not yet rendered / visible) – dannymilsom Nov 29 '17 at 17:19

0 Answers0