Skip to content

Instantly share code, notes, and snippets.

@BhavyaRattan
Last active January 21, 2021 12:10
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 BhavyaRattan/abf613094efce521d3b185a2ec64b603 to your computer and use it in GitHub Desktop.
Save BhavyaRattan/abf613094efce521d3b185a2ec64b603 to your computer and use it in GitHub Desktop.
Magic Touch Recycler
class ScaleItemOnTouchListener : RecyclerView.OnItemTouchListener {
.......
override fun onInterceptTouchEvent(rv: RecyclerView, event: MotionEvent): Boolean {
var interceptTouch = false
when (event.actionMasked) {
MotionEvent.ACTION_DOWN -> {
previousMotionX = event.x
previousMotionY = event.y
}
MotionEvent.ACTION_MOVE -> {
interceptTouch = !(abs(event.x - previousMotionX) > DRAG_THRESHOLD ||
abs(event.y - previousMotionY) > DRAG_THRESHOLD)
}
MotionEvent.ACTION_UP -> {
previousMotionX = 0f
previousMotionY = 0f
}
}
return interceptTouch
}
........
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment