Scrollbar jumping up and down with varying heights rows
Thought it was good to open a separate issue for this:
I have a RecyclerView that consists of varying heights TextViews (and some of the TextViews are larger than the full screen height).
When scrolling down using swiping (NOT using the fast scroll), I see the scrollbar jumping up and down as I scroll down.
Feels like the component needs a android:smoothScrollbar="false" like the ListView, but not entirely sure why it's happening... Any ideas?
I'm afraid that there is nothing I can do with it. I mean, to calculate the position of the scrollbar I have to calculate the expected height of the scrollable content. To do this I take the first item's height and multiply it by the number of items. So for items with extreme differences in height I won't be able to calculate the content's height accurately. If you had any idea how to fix this, a PR would be welcome. However I'm quite sure that it cannot be prevented entirely.
hmm
oops sorry closed this unintentionally. I think I might have an idea, I'll give it a go sometime this week and let you know.
Maybe it will inspire you. My initial idea to cope with it was to cache the size of elements which were already visible on the screen. When you scroll through the list you get to know to true size of each element. There is still a problem with the initial stage when you only see a few (or even one, like in your case) items. There are also edge cases for when you change the contents of the list. Generally not a reliable solution, I think...
So my idea was to just have clients implement an interface that informs the library of the size of each row based on the index. Looking at other libraries, I only found one that works reliably with rows with different heights:
https://github.com/turing-tech/MaterialScrollBar
Their approach is the same as my idea. I'm actually using that library for the time being and probably won't have time to implement my idea here, but if you or anyone else wants some inspiration, you can check out that library I linked.
It means that you know the height of the item upfront? So it would not work e.g. with wrap content items for which you don't know the height until they are inflated and populated with data?
In my case I actually don't know the heights but I calculate them before setting the adapter on the RecyclerView.
My rows are just TextViews so what I do is create a StaticLayout with exactly the same text and formatting as my TextView, and I measure the height. I then store this height and pass it to the adapter which now knows the heights of all the rows.
It is a bit expensive, I wish there was a way around it but I couldn't think/find another way..
Yeah, a lot of work, but if you require such behavior, probably the only way. I will leave this issue open, maybe someone will come up with an idea for something more versatile
Jump happens for SectionTitleProvider too when the header and content has different size. It will be more noticeable if we scroll slowly
hi, is this resolved or it has any workaround? This is also happening when the item size is more that total screen height. Its not displayed at first scroll, but once scrolled to height where second position is visible it is displayed