Created
November 14, 2022 03:16
-
-
Save cse-ariful/4ca4ddb0055225559fe3d416dbdef5d8 to your computer and use it in GitHub Desktop.
Extension Function to animate a views x,y and alpha. And get a callback after the animation completed
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
fun View.animateView(xTranslate: Float = 0f, yTranslate: Float = 0f, endAlpha: Float = 0f, duration: Long = 300, onEnd: (() -> Unit)? = null) = | |
try { | |
val listener = object : Animator.AnimatorListener { | |
override fun onAnimationStart(p0: Animator?) { | |
} | |
override fun onAnimationEnd(p0: Animator?) { | |
onEnd?.invoke() | |
} | |
override fun onAnimationCancel(p0: Animator?) { | |
} | |
override fun onAnimationRepeat(p0: Animator?) { | |
} | |
} | |
this.animate() | |
.translationX(width * xTranslate) | |
.translationY(height * yTranslate) | |
.alpha(endAlpha) | |
.setListener(listener) | |
.setDuration(duration) | |
.start() | |
}catch(ex:Exception){} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment