2

I am trying to animate some imageviews from color to grayscale and later from grayscale back to full.

This works fine but it doesn't animate:

        ColorMatrix matrixGrey = new ColorMatrix();
        matrixGrey.setSaturation(0);
        filterGrey = new ColorMatrixColorFilter(matrixGrey);

        ColorMatrix matrixFull = new ColorMatrix();
        matrixFull.setSaturation(1);
        filterFull = new ColorMatrixColorFilter(matrixFull);

        card1.setColorFilter(filterFull);
        card2.setColorFilter(filterGrey);

With the help of this post: Animate image's saturation i tried this to animate from full color to grayscale.

ValueAnimator animation = ValueAnimator.ofFloat(1f, 0f);
            animation.setDuration(10000);
//   animation.setInterpolator();
            animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    matrix.setSaturation(animation.getAnimatedFraction());
                    ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
                    v.setColorFilter(filter);
                }
            });
            animation.start();

It still animates from grayscale to color even if i changed the ofFloat values. What am i doing wrong here? card1, card2 and v is ImageViews.

Chris Myll
  • 21
  • 1

1 Answers1

0

Use animation.animatedValue instead of animation.animatedFraction

matrix.setSaturation(animation.animatedValue as Float)
DeNitE Appz
  • 1,003
  • 2
  • 12
  • 18