Created
January 21, 2021 12:13
-
-
Save BhavyaRattan/674e179d5e917816449272fbf1463f17 to your computer and use it in GitHub Desktop.
Magic Touch Recycler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ScaleItemOnTouchListener : RecyclerView.OnItemTouchListener { | |
....... | |
override fun onTouchEvent(rv: RecyclerView, event: MotionEvent) { | |
val childView = rv.findChildViewUnder(event.x, event.y) | |
val previousChild = rv.findChildViewUnder(previousX, previousY) | |
if (childView != null) { | |
when (event.action) { | |
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE -> { | |
if (childView.scaleX != SCALE_UP) { | |
scaleUp(childView) | |
} | |
if (previousChild != null && previousChild != childView) { | |
scaleDown(previousChild) | |
} | |
} | |
MotionEvent.ACTION_UP, MotionEvent.ACTION_POINTER_UP -> { | |
scaleDown(childView) | |
childView.callOnClick() | |
} | |
} | |
previousX = childView.x | |
previousY = childView.y | |
} else if (previousChild != null && (event.action == MotionEvent.ACTION_UP | |
|| event.action == MotionEvent.ACTION_CANCEL)) { | |
scaleDown(previousChild) | |
previousX = 0f | |
previousY = 0f | |
} | |
} | |
....... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment