Skip to content

Instantly share code, notes, and snippets.

@Atternatt
Last active September 21, 2017 04:57
Show Gist options
  • Save Atternatt/df3e20a5a0f281427dc4ee8ed7f00915 to your computer and use it in GitHub Desktop.
Save Atternatt/df3e20a5a0f281427dc4ee8ed7f00915 to your computer and use it in GitHub Desktop.
DelegatesAndExtensions
fun alphaWithBounceAnimator(): ReadWriteProperty<ImageView, Int> =
object : ReadWriteProperty<ImageView, Int> {
override fun getValue(thisRef: ImageView, property: KProperty<*>): Int {
return thisRef.imageAlpha
}
override fun setValue(thisRef: ImageView, property: KProperty<*>, value: Int) {
val animX = ObjectAnimator.ofFloat(thisRef, "scaleX", 1f, 2.5f, 1f)
val animY = ObjectAnimator.ofFloat(thisRef, "scaleY", 1f, 2.5f, 1f)
val alpha = ObjectAnimator.ofInt(thisRef.imageAlpha, value).apply {
addUpdateListener { thisRef.imageAlpha = it.animatedValue as Int }
}
if(thisRef.imageAlpha != value) {
AnimatorSet().apply {
playTogether(animX, animY, alpha)
duration = 250L
interpolator = AccelerateDecelerateInterpolator()
}.start()
}
}
}
var ImageView.imageAlfa: Int by alphaWithBounceAnimator()
imageView.imageAlfa = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment