Skip to content

Instantly share code, notes, and snippets.

@sagar-viradiya
Created August 15, 2017 11:53
Show Gist options
  • Save sagar-viradiya/16bd9079ba3e3d7172136f97e296b6a2 to your computer and use it in GitHub Desktop.
Save sagar-viradiya/16bd9079ba3e3d7172136f97e296b6a2 to your computer and use it in GitHub Desktop.
private fun setupOnTouchListener() {
...
android_bot.setOnTouchListener { view, motionEvent ->
if(motionEvent.action == MotionEvent.ACTION_MOVE) {
val deltaX = motionEvent.rawX - lastX
val deltaY = motionEvent.rawY - lastY
view.translationX = deltaX + view.translationX
view.translationY = deltaY + view.translationY
firstSpringAnimationX.animateToFinalPosition(view.translationX)
firstSpringAnimationY.animateToFinalPosition(view.translationY)
}
lastX = motionEvent.rawX
lastY = motionEvent.rawY
return@setOnTouchListener true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment