-
-
Save albodelu/c5ab72a72b2e52bc6040209d0930a08e to your computer and use it in GitHub Desktop.
DelegatesAndExtensions
This file contains hidden or 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 hidden or 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