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!
source share