Problems using RecyclerView with StaggeredLayoutManager

痞子三分冷 提交于 2019-12-13 16:47:18

问题


I succesfully implemented RecyclerView using StaggeredLayoutManager with 2 col/spans. I have variable heighted items in each col, heights are not fixed.

Problem is, when I scroll down and up in RecyclerView, sometimes a gap is occured at the top item of one of the rows. I added a video describing my problem.

I simply added a StaggeredLayout with span value 2, and adapted my items with an adapter.

+-+-+-+-+-+-+-+-+-+-+-+-+ <------ Top of RecyclerView

--------------                    <- Top item in left column

                   ------------- <- Top item in right column, has unexpected gap/offset/margin at top. Gap sometimes occurs. Sometimes, everything is well aligned and no problems.

Here is the video I take from my application. https://youtu.be/gmB7h73YR3M

Look at the topmost 2 pictures(LinearLayouts) in the list, cup and monitor. Their top position differs after each scroll down and then up event, and an unwanted grey area (Backgroundcolor of RecyclerView) appears at there.

Between 0-3 sec, there is a gap on top of cup, left column.

Between 7-8, there is a gap but little than 0-3

Between 10-12, everything is fine, their tops are at same level.

Between 19-21, this time right column has a gap on top.

Any reasons why I have this problem, any solutions?

EDIT: Because I don't want so much moving items, I set gapping strategy as GAP_HANDLING_NONE. However, when I set strategy as GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS, toppest line of two items get aligned when Scrolling Up ends at top. My observation is, when scrolling to the elements at top, a last calculation is made to Align top lines of 2 items if strategy is GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS, but not in GAP_HANDLING_NONE. I can see it is aligned with my eyes, but it doesn't seem to happen when strategy is GAP_HANDLING_NONE.

来源:https://stackoverflow.com/questions/35565743/problems-using-recyclerview-with-staggeredlayoutmanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!