Android - AnimatorSet, Object Animator - Does the Bounce animation chain merge?

I have a question regarding ObjectAnimator in Android. I'm trying to simulate the Bounce effect, whereby the view slides up (decreases the Y value) and returns down the same amount of "n" followed by a "Move up" up and down, but this time "n / 2" (so on half the distance).

So, a larger bounce, followed by a smaller bounce, i.e. something like a Mac icon in a tray when it wants your attention.

Here is what I have tried so far (suppose v is View ):

 float y = v.getTranslationY(),distance = 20F; AnimatorSet s = new AnimatorSet(); s.play(ObjectAnimator.ofFloat(v, "translationY", y- distance).setDuration(500)) .before(ObjectAnimator.ofFloat(v, "translationY", y).setDuration(500)) .before(ObjectAnimator.ofFloat(v, "translationY", y- (distance/2)).setDuration(500)) .before(ObjectAnimator.ofFloat(v, "translationY", y).setDuration(500)); s.start(); 

Ignore the quality of the code, this is POC! I was hoping this would work, but it looks like it only โ€œbouncesโ€ as if it were .before() animations despite using .before() .

Could you show me how I can create complex AnimatorSet chains that are not combined into one, since I seem to be missing something?

BONUS: For additional points, how can I set the repeat of AnimatorSet?

Many thanks!

+6
source share
2 answers

OK, so I found a pretty neat way to achieve consistent animation, ignoring the free builder, and just using the playSequentially() method, which:

 AnimatorSet as = new AnimatorSet(); as.playSequentially(ObjectAnimator.ofFloat(...), // anim 1 ObjectAnimator.ofFloat(...), // anim 2 ObjectAnimator.ofFloat(...), // anim 3 ObjectAnimator.ofFloat(...)); // anim 4 as.setDuration(600); as.start(); 

However, it was not possible to repeat the repetition except for a dirty hack with the onAnimationEnd callback in the listener. There should be a simpler way, so maybe someone can edit this when they find out about it.

Anyway, hope this helps someone.

+16
source

When you use Builder, all returned dependencies refer to the first animator, so after the first move you had 3 bounces. Unfortunately, it seems that AnimatorSet is broken into several aspects, one of which is repeated: https://code.google.com/p/android/issues/detail?id=17662

+3
source

All Articles