Skip to content

Instantly share code, notes, and snippets.

@bitvale
Created May 4, 2019 14:07
Show Gist options
  • Save bitvale/753dcfaf985e07615c60ca4ad65d9d82 to your computer and use it in GitHub Desktop.
Save bitvale/753dcfaf985e07615c60ca4ad65d9d82 to your computer and use it in GitHub Desktop.
For Medium article "Animate Everything! (Android Animation Showcase)"
override fun onDraw(canvas: Canvas) {
canvas?.drawOval(defRect, backgroundPaint)
canvas?.drawOval(animatedRect, foregroundPaint)
}
fun startAnimation() {
// ...
val animateLeft = ObjectAnimator.ofFloat(animatedRect, "left", animatedRect.left, toRect.left)
val animateTop = ObjectAnimator.ofFloat(animatedRect, "top", animatedRect.top, toRect.top)
val animateRight = ObjectAnimator.ofFloat(animatedRect, "right", animatedRect.right, toRect.right)
val animateBottom = ObjectAnimator.ofFloat(animatedRect, "bottom", animatedRect.bottom, toRect.bottom)
val foregroundColorAnimator = ValueAnimator().apply { /* init animator */ }
val backgroundColorAnimator = ValueAnimator().apply { /* init animator */ }
animatorSet.apply {
// init animator set
playTogether(animateLeft, animateTop, animateRight, animateBottom, foregroundColorAnimator, backgroundColorAnimator)
duration = ANIMATION_DURATION
start()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment