我一直在努力实现这一目标。我想要的是从左到右重叠所选的RecyclerView
项目,如下图所示。
我可以通过ItemDecoration
向左或向右移动,如下所示:
class OverlapDecoration(private val overlapWidth:Int) : RecyclerView.ItemDecoration() {
private val overLapValue = -40
val TAG = OverlapDecoration::class.java.simpleName
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State?) {
val itemPosition = parent.getChildAdapterPosition(view)
if (itemPosition == 0) {
return
} else {
outRect.set(overLapValue, 0, 0, 0)
}
}
}
我已经尝试使用CarouselLayoutManager,但不是我想要的。
答案 0 :(得分:0)
要获得所需的结果,您需要执行两个步骤:
首先,更正装饰器计算:
if (itemPosition == 0) {
return
} else {
outRect.set(-1 * overLapValue, 0, overLapValue, 0) //Need left, AND right
}
第二,您需要实际添加阴影
并且,对该类进行了一些快速的清理,您不需要private val overLapValue
。
相反:
class OverlapDecoration(private val overlapWidth:Int = 40) : RecyclerView.ItemDecoration() {