Skip to content

Instantly share code, notes, and snippets.

@Skyyo
Last active August 8, 2020 16:48
Show Gist options
  • Save Skyyo/01799c36cf10aa31d45e408533f2e9d6 to your computer and use it in GitHub Desktop.
Save Skyyo/01799c36cf10aa31d45e408533f2e9d6 to your computer and use it in GitHub Desktop.
#extensions
package com.skyyo.ext
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.view.View
fun View.bounceIn(): AnimatorSet {
val animatorSet = AnimatorSet()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f, 1f, 1f)
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "scaleX", 0.3f, 1.05f, 0.9f, 1f)
val object3: ObjectAnimator = ObjectAnimator.ofFloat(this, "scaleY", 0.3f, 1.05f, 0.9f, 1f)
animatorSet.playTogether(object1, object2, object3)
return animatorSet
}
fun View.bounceInLeft(): AnimatorSet {
val animatorSet = AnimatorSet()
val width = -width.toFloat()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationX", width, 30f, -10f, 0f)
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f, 1f, 1f)
animatorSet.playTogether(object1, object2)
return animatorSet
}
fun View.bounceInRight(): AnimatorSet {
val animatorSet = AnimatorSet()
val width = -width.toFloat()
val measured_width = -measuredWidth.toFloat()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationX", measured_width + width, -30f, 10f, 0f)
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f, 1f, 1f)
animatorSet.playTogether(object1, object2)
return animatorSet
}
fun View.bounceInUp(): AnimatorSet {
val animatorSet = AnimatorSet()
val measured_height = measuredHeight.toFloat()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationY", measured_height, -30f, 10f, 0f)
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f, 1f, 1f)
animatorSet.playTogether(object1, object2)
return animatorSet
}
fun View.bounceInDown(): AnimatorSet {
val animatorSet = AnimatorSet()
val height = -height.toFloat()
val object1: ObjectAnimator = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f, 1f, 1f)
val object2: ObjectAnimator = ObjectAnimator.ofFloat(this, "translationY", height, 30f, -10f, 0f)
animatorSet.playTogether(object1, object2)
return animatorSet
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment