ShadowMare ShadowMare - 4 months ago 65x
Android Question

android animation is not finished in onAnimationEnd

It seems that an android animation is not truly finished when the

event is fired although
is set to true.

I want my view to change it's background drawable on the end of it's
which it does, but you can clearly see that it is changed some miliseconds before it finishes. The problem is, that it flickers because the new background appears (=is) scaled for a short time until the animation really finishes.

Is there a way to get either the real end of the animation or just prevent the new background from beeing scaled this short period of time?

Thank you!

//EDIT: I'm using an
to get the following call:

public void onAnimationEnd(Animation animation)
View view = (MyView) ((ExtendedScaleAnimation) animation).getView();

view.refreshBackground(); // <-- this is where the background gets changed


Here is the actual bug related to this issue

This basically states that the onAnimationEnd method doesn't really work well when an AnimationListener is attached to an Animation

The workaround is to listen for the animation events in the view to which you were applying the animation to For example if initially you were attaching the animation listener to the animation like this

mAnimation.setAnimationListener(new AnimationListener() {
    public void onAnimationEnd(Animation arg0) {
        //Functionality here

and then applying to the animation to a ImageView like this


To work around this issue, you must now create a custom ImageView

public class MyImageView extends ImageView {

and then override the onAnimationEnd method of the View class and provide all the functionality there

protected void onAnimationEnd() {
    //Functionality here

This is the proper workaround for this issue, provide the functionality in the over-riden View -> onAnimationEnd method as opposed to the onAnimationEnd method of the AnimationListener attached to the Animation.

This works properly and there is no longer any flicker towards the end of the animation. Hope this helps.