Adam Katz Adam Katz - 1 month ago 7
Android Question

is there a TranslateAnimation onComplete?

I am animating a view to move off the screen, on complete i would like to call another function but I cant seem to find a onComplete method.

int originalPos[] = new int[2];
icons.getLocationOnScreen( originalPos );
layoutMoved = originalPos[0]+icons.getWidth();
TranslateAnimation anim = new TranslateAnimation( 0, -layoutMoved , 0, 0);
anim.setDuration(500);
anim.setFillAfter( true );
icons.startAnimation(anim);
icons.setVisibility(View.GONE);

Answer

Set an AnimationListener, you'll have access to OnAnimationEnd.

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

    }

    @Override
    public void onAnimationEnd(Animation animation) {
       // do your stuff
    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }
});