Search code examples
javaandroidanimationcallbacktranslate-animation

Get animate().translation Callback When Animation Is Complete


I've been looking around and the main ways seem to be setting an animation listener on the object. However I have set an animation listener and the animation complete callback does not fire.

Do you know how I can get the callback when an view.animate().translationY() has finished its animation?

root.setLayoutAnimationListener
        (
                new Animation.AnimationListener()
                {
                    @Override
                    public void onAnimationStart(Animation animation)
                    {

                    }

                    @Override
                    public void onAnimationEnd(Animation animation)
                    {
                        closeFragmentAnimationComplete(); //is not called
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation)
                    {

                    }
                }
        );

root.animate().translationY(100);

Solution

  • Please try:

    view.animate().translationY(100).setListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {}
    
                @Override
                public void onAnimationEnd(Animator animation) {
                    closeFragmentAnimationComplete();
                }
    
                @Override
                public void onAnimationCancel(Animator animation) {}
    
                @Override
                public void onAnimationRepeat(Animator animation) {}
            });