Closed GauthierChan closed 6 years ago
Yeah, getChildAt(0).height
should take into account at least the orientation
value.
@GauthierChan this issue was automatically marked as fixed by the commit, but I wanted to thank you for writing this issue and all the cases, it made my job a lot easier and faster. Thanks again!
Hi :)
Another case of items not being drawn when scrolling up, I followed #19 and #15 and it solved it for most configurations but I found new cases where it doesn't work.
In the GIFs below I have a SpannedGridLayoutManager with a 4-width span. I mix 2x2, 1x1 and 4x1 blocks.
Working case
Just one 2x2 block and it works fine:
Non working case
Same as above but more 1x1 blocks after the 2x2 blocks
Two "intertwined" 2x2 blocks
Two adjacent 2x2 blocks
Possible solution
In SpannedGridLayoutManager#fillBefore(), if I remove the
canAddMoreViews(Direction.START, limit)
condition as such:Then scrolling up doesn't seems to have drawing problems. But it has huge performance issues as I guess it draws all views that are above the current start 😄
So I found a hotfix to make the LayoutManager draw only necessary views:
It makes the canAddMoreViews() more acceptable as of to when the LayoutManager should add a view at the top. Basically second-checking when it looks like there's not going to be any more views at the top 😄
The
-getChildAt(0).height
is totally arbitrary though, and might not work if views on the same column don't have the same height. And it is an ugly hotfix as it doesn't solve the original problem of why views weren't added. Do you have any ideas on how to improve this ?This also seems to make scrolling up working without having to add an ItemDecoration to the RecyclerView.
Here's an Adapter where you can reproduce the layouts I showed above. Change the
onBindViewHolder()
example call methods (They are in the same order as above) for the layout you want 😃