【发布时间】:2022-03-15 17:53:25
【问题描述】:
我有一个与 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最初设置的边距不存在了
你能帮我解决这个问题吗?
谢谢
编辑: 我猜这可能是视图回收的结果,因为我看到滚动后其他项目现在有顶部偏移,即使我不打算为它们设置它
【问题讨论】:
标签: android-recyclerview android-flexboxlayout item-decoration