End animation event android

Paulo Barros picture Paulo Barros · Sep 30, 2011 · Viewed 69.5k times · Source

I have a fadeout animation in a view (which is inside a fragment), and everytime the animation happens, after it finishes the view redraws itself again. I found a work around doing view.SetVisibility(View.GONE) . But it doesn't wait for the animation to finish. I would like to execute this setVisibility code only after the animation has finished. What is the best way to do that?

Answer

blessenm picture blessenm · Sep 30, 2011

You can add Animation listener to your animation object like

anim.setAnimationListener(new Animation.AnimationListener(){
    @Override
    public void onAnimationStart(Animation arg0) {
    }           
    @Override
    public void onAnimationRepeat(Animation arg0) {
    }           
    @Override
    public void onAnimationEnd(Animation arg0) {
    }
});