There is a task - to smoothly change the ImageView color according to the colors from the specified array. To solve the problem, a subclass of ImageView was created and ObjectAnimator is launched during initialization:
public class ImageAnimate extends ImageView { private ObjectAnimator colorAnimator; private int[] colors = new int[]{ 0xff0988c9, 0xff93ba1f, 0xfffdc466, 0xffec1e7a }; private final TypeEvaluator ARGB_EVALUATOR = new ArgbEvaluator(); public ImageAnimate(Context context, AttributeSet attrs) { super(context, attrs); colorAnimator = ObjectAnimator.ofInt(this, colorProperty, colors) .setDuration(1000 * colors.length); colorAnimator.setEvaluator(ARGB_EVALUATOR); colorAnimator.setInterpolator(new LinearInterpolator()); colorAnimator.setRepeatCount(ValueAnimator.INFINITE); colorAnimator.setRepeatMode(ValueAnimator.INFINITE); colorAnimator.start(); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); colorAnimator.start(); } @Override protected void onDetachedFromWindow() { if (colorAnimator != null) { colorAnimator.cancel(); } super.onDetachedFromWindow(); } private Property<ImageAnimate, Integer> colorProperty = new Property<ImageAnimate, Integer>(Integer.class, "color") { @Override public Integer get(ImageAnimate object) { return null; } @Override public void set(ImageAnimate object, Integer value) { object.setColorFilter(value); } }; }
It works fine, but when you repeat the iteration and the last color to the first, there is not a smooth gradient transition, but a sharp jump. Can you please tell me how to persuade ObjectAnimator to move to a new circle smoothly?