动画[5]PropertyAnimator AnimatorSet

来源:互联网 发布:coc2017城墙升级数据 编辑:程序博客网 时间:2024/06/03 22:42

【参考链接】

 

还可以使用AnimatorSet将多个ValueAnimator/ObjectAnimator组合到一起

可以通过如下方式来控制多个动画的协作方式

.play(anim1).with(anim2)//同时执行

                    .before(anim2)//先执行anim1,再执行anim2

                    .after(anim2)//先执行anim2,再执行anim1

.playTogether(anim1,anim2)

.playSequentially(anim1,anim2)

 

并且,参见《View[7] Property》,由于ViewProperty之间是相互独立的,因此跟TweenAnimationAnimationSet不同,AnimatorSet可以实现一边移动一边旋转的效果。

 

ValueAnimatoranimator1 = ValueAnimator.ofArgb(/*RED*/0xFFFF8080,/*BLUE*/0xFF8080FF);
animator1.addUpdateListener(
       
newValueAnimator.AnimatorUpdateListener() {
           
@Override
           
public voidonAnimationUpdate(ValueAnimator animator) {

               
intanimatedValue = (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=newAnimatorSet();
set.playTogether(animator1,animator2,animator3,animator4);
set.setDuration(3000);
set.start();

 


 

原创粉丝点击