Created
June 14, 2020 07:45
-
-
Save guyca/82568355b183b0ec505356f54b10b7a1 to your computer and use it in GitHub Desktop.
An animator responsible for animating a views X coordinate
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 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