使用 getItemOffsets 设置的偏移量在滚动后消失

问题描述

我有一个与 FlexLayoutManager 配合使用的水平 RecyclerView。我也有一些带有 RecyclerView.Itemdecoration 的装饰品。 我的 getItemOffsets 方法看起来像这样:

override fun getItemOffsets(outRect: Rect,view: View,recyclerView: RecyclerView,state: RecyclerView.State) {
  super.getItemOffsets(outRect,view,recyclerView,state)
  val position: Int = recyclerView.getChildAdapterPosition(view)
  if(position meets some rules){
    outRect.top = some values here
  }

  if(viewType == CERTAIN_VIEW_TYPE){
    outRect.bottom = some value
  }
}

 ..onDrawOver(){ 
     //I draw the decorations here
   }

这有效,显示了我设置为装饰的视图,并且它们位于正确的位置。

我遇到的问题是,在我向右滚动然后向左滚动后,outRect.top 设置的偏移量设置为 0,并且我的装饰与我的项目重叠。

奇怪的是,outRect.bottom 设置的偏移量不会消失或导致任何问题。

我只是指定 outRect.top 设置的偏移量仅针对某些位置设置。

我的装饰也没有消失,只是最初由 outRect.top 设置的边距不再存在

你能帮我解决这个问题吗?

谢谢

编辑: 我猜这可能是视图回收的结果,因为我看到滚动后其他项目现在有顶部偏移,即使我不打算为它们设置

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)