Start multiple ViewPropertyAnimators at the same time

Jakob picture Jakob · Aug 9, 2014 · Viewed 10.4k times · Source

With the Animator class you can simply call something like the following to play multiple animations simultaneously:

AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(animatorsArray);
animatorSet.start();

But I cannot find anything similar which would work with ViewPropertyAnimator.

(FYI. I am trying to animate multiple listView items)

Answer

Bartek Lipinski picture Bartek Lipinski · Sep 22, 2015

I know the question is more than one year old, but since I needed the same thing and I came up with a solution I decided to share it:

I've created an ObjectAnimator wrapper which you can use in almost exactly the same manner as you would use ViewPropertyAnimator. And still, you can use the ObjectAnimator object so you can write your AnimatorSet.

The wrapper is available here.

Example (setting up an animation of the same parameters for a mTestView):

  1. ViewPropertyAnimator

mTestView.animate().withLayer().alphaBy(0.3f).rotationX(27);
  1. ViewPropertyObjectAnimator (my wrapper)

ObjectAnimator objectAnimator = 
    ViewPropertyObjectAnimator.animate(mTestView).withLayer().alphaBy(0.3f).rotationX(27).get();

and you have an ObjectAnimator which you can either just start() or use inside AnimatorSet.