Skip to content

Instantly share code, notes, and snippets.

@le0nidas
Created May 9, 2021 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save le0nidas/7f5ed4ba87690895545057c2096f451f to your computer and use it in GitHub Desktop.
Save le0nidas/7f5ed4ba87690895545057c2096f451f to your computer and use it in GitHub Desktop.
list.addOnItemTouchListener(
object : RecyclerView.SimpleOnItemTouchListener() {
var initialX = 0f
var initialY = 0f
override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
if (e.action == MotionEvent.ACTION_DOWN) {
rv.parent.requestDisallowInterceptTouchEvent(true)
initialX = e.rawX
initialY = e.rawY
} else if (e.action == MotionEvent.ACTION_MOVE) {
val xDiff = abs(e.rawX - initialX)
val yDiff = abs(e.rawY - initialY)
if (yDiff > xDiff) {
rv.parent.requestDisallowInterceptTouchEvent(false)
}
}
return super.onInterceptTouchEvent(rv, e)
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment