Shivam Gupta
Shivam Gupta

Reputation: 1

How to perform an action just before and after the animation

I want to perform some actions just before and just after an animation. Here is my code:-

AnimatorSet set1 = new AnimatorSet();
set1.playTogether(
    ObjectAnimator.ofFloat(ball1, "translationX", x1, xn),
    ObjectAnimator.ofFloat(ball1, "translationY", y1, yn),
    ObjectAnimator.ofFloat(ball2, "translationX", xn, x1),
    ObjectAnimator.ofFloat(ball2, "translationY", yn, y1)

);
set1.setDuration(1000).start();

Is there any animator set method to do that.??

Upvotes: 0

Views: 399

Answers (1)

Illegal Argument
Illegal Argument

Reputation: 10358

You can use setAnimationListener for this:

set.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator arg0) {
            // TODO Auto-generated method stub
            //code when starting animation
        }

        @Override
        public void onAnimationRepeat(Animator arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationEnd(Animator arg0) {
            // TODO Auto-generated method stub
            //code on animation end
        }

        @Override
        public void onAnimationCancel(Animator arg0) {
            // TODO Auto-generated method stub

        }
    });

Upvotes: 1

Related Questions