I'm trying to make two animations on the same view: one for the backgroundTint and one for the scale... Using ObjectAnimator.ofPropertyValuesHolder
makes the most sense, as you can just list propertyValueHolder that represent the animations. I have something like this:
val enabledColor = context.getColor(R.color.colorAccent)
val disabledColor = context.getColor(R.color.colorDisabled)
val anim = ObjectAnimator.ofPropertyValuesHolder(imgBackground,
PropertyValuesHolder.ofFloat(View.SCALE_X, 1F, 1.2F),
PropertyValuesHolder.ofFloat(View.SCALE_Y, 1F, 1.2F),
PropertyValuesHolder.ofInt("colorFilter", enabledColor, disabledColor)
)
However, the colorFilter
(which is the background tint) is not being animated properly as it's animating an Int... When the animation plays the background_tint is all over the place: yellow, green, etc. I would like to keep this style - using ObjectAnimator to group all the animations.
Previously, I had:
ObjectAnimator.ofArgb(imgBackground, colorAnimProperty, disabledColor, enabledColor)
val scaleUpAnim = ObjectAnimator.ofPropertyValuesHolder(imgBackground,
PropertyValuesHolder.ofFloat(View.SCALE_X, 1F, 1.2F),
PropertyValuesHolder.ofFloat(View.SCALE_Y, 1F, 1.2F)
)
Which does the trick, but it's inconvenient as I need an AnimationSet to combine them...
How can I write the background_tint animation using a PropertyValuesHolder
?
Found out that we can supply the PropertyValuesHolder
with an Evaluator function that does the calculation for us. Conveniently, there's an ArgsEvaluator. Hence, it looks like this:
animEnable = ObjectAnimator.ofPropertyValuesHolder(imgBackground,
PropertyValuesHolder.ofFloat(View.SCALE_X, 1F, 1.2F),
PropertyValuesHolder.ofFloat(View.SCALE_Y, 1F, 1.2F),
PropertyValuesHolder.ofObject("colorFilter", ArgbEvaluator(), disabledColor, enabledColor))