Skip to content

Instantly share code, notes, and snippets.

@guyca
Created June 14, 2020 07:45
Show Gist options
  • Save guyca/82568355b183b0ec505356f54b10b7a1 to your computer and use it in GitHub Desktop.
Save guyca/82568355b183b0ec505356f54b10b7a1 to your computer and use it in GitHub Desktop.
An animator responsible for animating a views X coordinate
class XAnimatorCreator(from: View, to: View) : PropertyAnimatorCreator(from, to) {
private val dx: Int
init {
val fromXy = ViewUtils.getLocationOnScreen(from)
val toXy = ViewUtils.getLocationOnScreen(to)
dx = fromXy.x - toXy.x
}
override fun shouldAnimateProperty() = dx != 0
override fun create(): Animator {
return ObjectAnimator.ofFloat(to, TRANSLATION_X, dx.toFloat(), 0f)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment