Skip to content

Instantly share code, notes, and snippets.

@JulienArzul
Created July 11, 2018 06:09
Show Gist options
  • Save JulienArzul/5700ce1072a7ea972e26b13691a56e68 to your computer and use it in GitHub Desktop.
Save JulienArzul/5700ce1072a7ea972e26b13691a56e68 to your computer and use it in GitHub Desktop.
RecyclerView class that supports drawing fading edges with clipToPadding=false
package com.julienarzul.android.recyclerview
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
class FadingEdgeRecyclerView : RecyclerView {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
override fun isPaddingOffsetRequired(): Boolean {
return !clipToPadding
}
override fun getLeftPaddingOffset(): Int {
return if (clipToPadding) 0 else -paddingLeft
}
override fun getTopPaddingOffset(): Int {
return if (clipToPadding) 0 else -paddingTop
}
override fun getRightPaddingOffset(): Int {
return if (clipToPadding) 0 else paddingRight
}
override fun getBottomPaddingOffset(): Int {
return if (clipToPadding) 0 else paddingBottom
}
}
@joh-lin
Copy link

joh-lin commented Feb 20, 2022

thanks bro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment