Nik
Nik

Reputation: 3133

applyTransformation called after onAnimationEnd in Android

I have a custom View and a custom Animation. My custom view overrides onAnimationEnd and my custom Animation class overrides applyTransformation respectively.

I found that applyTransformation is still getting called after onAnimationEnd is called.

I tried using the solution provided here, but still it's not working.

Upvotes: 2

Views: 1234

Answers (1)

Jim
Jim

Reputation: 833

I ran into this issue a while back and traced it back to an issue on Android's bug tracker. I'm not sure if it's still there or if it has been fixed but in the mean time I worked around it with a slight hack:

class SomeClass {
    private bool mAnimationEnded = true;

    private void SomeMethod() {
        Animation animation = new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
                if (mAnimationEnded) return;
                // ...
            }
        }

        animation.setAnimationListener(new AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                mAnimationEnded = true;
                // ...
            }

            @Override 
            public void onAnimationStart(Animation animation) {
                mAnimationEnded = false;
                // ...   
            }

            @Override
            public onAnimationRepeat(Animation animation) { }
        }
        // ... Use animation here
    }
}

Upvotes: 2

Related Questions