Chain animatorSet android animation

2019-08-06 08:50发布

问题:

New to android i would like to make some smooth animation.

I have a file on device that contains effects and each effect is an animation. The file tells me when an effect will be played and the effect duration.

The problem is i cannot chain animatorSet dynmacily :

AnimatorSet mainAnimatorSet(); 
_listAllAnimator // Will contain every AnimatorSet(); 
for (int i = 0; i < listEffects; i++)
{
// Build animatorSet 
   ObjectAnimaTor1... 
   ObjectAnimaTor2... 
   AnimatorSet animatorSet = new AnimatorSet(); 
   animatorSet.play(ObjectAnimaTor1).with(ObjectAnimaTor2); 
   _listAllAnimator.add(animatorSet);

}

Now how can i want mainAnimatorSet() from my list of AnimatorSet(); each animations start at the end of the last one.

for (int i = 0; i < _listAllAnimator.size(); i++)
{
if (i==0) {
  mainAnimatorSet.play(animSet.get(i));
}
else {
    mainAnimatorSet.play(animSet.get(i)).after(animSet.get(i-1)); 
}
}
mainAnimatorSet.start(); 

This does not work. Thanks

回答1:

i dont really get you but i am posting an answer anyway..

1 supposing you you have animations in an arraylist or list and you want to play those animations in order of start-after-previous-end

AnimatorSet s = new AnimatorSet();
s.playSequentially(List<Animator> items); // items is your arraylist of animations

2 supposing you you have animations in an arraylist or list and you want to play those animations at the same time

AnimatorSet s = new AnimatorSet();
s.playTogether(List<Animator> items); // items is your arraylist of animations