Skip to content Skip to sidebar Skip to footer

How To Apply Itemdecoration From Left And Right Side Both To Recyclerview Item?

I have been trying to achieve this for so long. What I want is to overlap the selected RecyclerView item from left and right as shown in the picture below. I'm able to achieve le

Solution 1:

To achieve the result you're looking for you need to take two steps:

First, to correct the decorator calculations:

if (itemPosition == 0) {
    return
} else {
    outRect.set(-1 * overLapValue, 0, overLapValue, 0) //Need left, AND right
}

Second, you need to actually add the shadow

And, one quick bit of cleanup for the class, you don't need the private val overLapValue.

Instead:

classOverlapDecoration(private val overlapWidth:Int = 40) : RecyclerView.ItemDecoration() {

Post a Comment for "How To Apply Itemdecoration From Left And Right Side Both To Recyclerview Item?"