3

I have a RecyclerView with custom LayoutManager that handles the photo laying out so the result is different in portrait and landscape as you can see in the images below.

Now everything is working fine except for when I handle onConfigurationChanged() callback from portrait to landscape and vice-versa.

I want to save state of recyclerView so when user flips the device I will scroll the recyclerview to the same spot he was before rotating.

If you will notice the photos below, the landscape working fine but when I switch to portrait it does scroll to the last position the user where (notice the red car and it is rationally logical since this is what I wanted) but except for one problem, it looks as if the recyclerview is getting suddenly extra white space at the bottom.

Portrait Landscape

I would like to avoid it and get the recyclerview to the bottom of its content (the red car is not the first item in the data set, I have plenty more before it) without actually taking the user to his last item if the position scrolled to is getting the recyclerview to "expand".

How can I calculate if the scrollToPosition() is "expanding" the recyclerview over its content height ? If I remember correctly it does not happen in LinearLayoutManager or GridLayoutManager.

I only need to know if the position that is laying out has enough space before actually scrolling to it and eventually scrolls to a minimum one that does not gives the white space at the bottom, but I don't know how.

Side note: If I scroll it up and then down again it does stay at the bottom without the extra white space.

Gilad Eshkoli
  • 1,253
  • 11
  • 27

0 Answers0