【参考链接】
还可以使用AnimatorSet将多个ValueAnimator/ObjectAnimator组合到一起
可以通过如下方式来控制多个动画的协作方式
.play(anim1).with(anim2)//同时执行
.before(anim2)//先执行anim1,再执行anim2
.after(anim2)//先执行anim2,再执行anim1
.playTogether(anim1,anim2)
.playSequentially(anim1,anim2)
并且,参见《View[7] Property》,由于View的Property之间是相互独立的,因此跟TweenAnimation的AnimationSet不同,AnimatorSet可以实现一边移动一边旋转的效果。
ValueAnimatoranimator1 = ValueAnimator.ofArgb(/*RED*/0xFFFF8080, /*BLUE*/0xFF8080FF);
animator1.addUpdateListener(
new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
int animatedValue = (int) animator.getAnimatedValue();
tv.setBackgroundColor(animatedValue);
}
});
ObjectAnimatoranimator2 = ObjectAnimator.ofFloat(tv, "translationY", 100, 300);
ObjectAnimatoranimator3= ObjectAnimator.ofFloat(tv, "rotation", 0, 360);
ObjectAnimator animator4=ObjectAnimator.ofFloat(tv, "scaleX", 1, 0.5f);
AnimatorSet set=new AnimatorSet();
set.playTogether(animator1, animator2, animator3, animator4);
set.setDuration(3000);
set.start();