3
votes

I've created a extension to the Animation class in order to create a background fade out animation. I start the animation after pressing a ListView row item. If I press one after another I want to cancel the first animation and start the second. But a bug that I'm having is when I press fast one row after another the animation doesn't stop. After debugging I've noticed that the applyTransformation method keeps running for the first animation. I've decided to override the cancel function, but how do I stop the transformation?

public BackgroundAnimation(View view, int color){
    this.view = view;
    setDuration(4000L);

    red = Color.red(color);
    blue = Color.blue(color);
    green = Color.green(color);
}
@Override
public void applyTransformation(float interpolatedTime,Transformation t){
    //super.applyTransformation(interpolatedTime, t);

    view.setBackgroundColor(Color.argb((int) ((1 - interpolatedTime) * 255), red, green, blue));

}
1
have you tried clearAnimation()? - pskink
it should work, why do you think it doesn't? - pskink
no idea, I thought I've implemented my custom animation class not as it should be. or not fully !? - RCB
so interpolatedTime goes always 0 -> 1? - pskink
the method keeps running with interpolatedTime 0 if I run the cancel method. if I call the clearAnimation than yes it runs from 0 -> 1. - RCB

1 Answers

2
votes

I had the exact same problem, interpolatedTime would run 0 -> 1 then infinitely repeat for 0. My solution was to clearAnimation in an AnimationListener. It doesn't seem like you should have to do this, but oh well.

animation.setAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationStart(Animation animation) {}

    @Override
    public void onAnimationEnd(Animation animation) {
        animationTarget.clearAnimation();
    }

    @Override
    public void onAnimationRepeat(Animation animation) {}
});