I use recycler view decoration to add margin before specific items.
My items - mostly MaterialCardView - have an important elevation : 16dp (thanks to our UI guys...)
Elevations are allowed to be drawn outside item view container with
android:clipChildren="false"
android:clipToPadding="false"
My problem is : elevation is truncated by recycler view decoration.
here decoration code :
class TopSpacingItemDecoration(context: Context) : RecyclerView.ItemDecoration() {
private val spacing = context.resources.getDimension(R.dimen.margin_before_section)
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
val position = parent.getChildAdapterPosition(view)
val type = adapter.getItemViewType(position)
if (type == adapter.SPECIFIC_TYPE || other conditions) {
outRect.set(0, spacing.toInt(), 0, 0)
}
}
}
It looks like :
FYI : I don't want to manage margins on item because recycler view order is dynamic
Any idea how fix this ?
