Last active
September 21, 2017 04:57
-
-
Save Atternatt/df3e20a5a0f281427dc4ee8ed7f00915 to your computer and use it in GitHub Desktop.
DelegatesAndExtensions
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 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() |
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
imageView.imageAlfa = 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment