2

Hi I'm trying to do a series of animations but it's failing miserably. It worked fine when it was just 4.0 but I added support for 2.2 and 2.3 using nineoldandroid. it seamed to work but the AnimatorListener's method onAnimationEnd is called twice.

This is the code I'm using for the animation:

animate(horizontalView)
   .translationX(xDelta)
   .setDuration(2000)
   .setListener(new Animator.AnimatorListener() {
      //listener implementation onAnimationEnd
      @Override
      public void onAnimationEnd(Animator animator) {
         animate(droppingView)
              .translationY(yDelta)
              .setDuration(2000)
              .setListener(null)
              .start();
      }
   }).start();

The first animation fires its listener twice and the second animation 3 times. This only happens on 2.2 and 2.3 from what I've tested.

Gravitoid
  • 1,294
  • 1
  • 20
  • 20
Hugo Alves
  • 1,555
  • 2
  • 18
  • 41

1 Answers1

2

Have you tried removing the old listener

animate(horizontalView)
   .translationX(xDelta)
   .setDuration(2000)
   .setListener(new Animator.AnimatorListener() {
      //listener implementation onAnimationEnd
      @Override
      public void onAnimationEnd(Animator animator) {
         animator.removeListener(this); // << this
         animate(droppingView)
              .translationY(yDelta)
              .setDuration(2000)
              .setListener(null)
              .start();
      }
   }).start();
Blundell
  • 75,855
  • 30
  • 208
  • 233
  • 1
    yes i've tried. apparenty the class `ViewPropertyAnimatorPreHC` used por older android class a different listener then that one. I had to save the instance of `animate(horizontalView)` and do `.setListener(null)`. what i can see that happend is that it fires the listener for each property animated... or something like that – Hugo Alves Jul 04 '14 at 11:23