AnimatorSet set = new AnimatorSet() ; ObjectAnimator anim = ObjectAnimator .ofFloat(phone, "translationX", -500f, 0f); anim.setDuration(2000); ObjectAnimator anim3 = ObjectAnimator .ofFloat(phone, "translationX", 0f, -500f); anim3.setDuration(2000); ObjectAnimator anim2 = ObjectAnimator .ofFloat(phone, "translationY", 0f, -500f); anim2.setDuration(2000); ObjectAnimator anim4 = ObjectAnimator .ofFloat(phone, "translationY", -500f, 0f); anim4.setDuration(2000); AnimatorSet set3 = new AnimatorSet(); set3.play(anim4).before(anim3) ; AnimatorSet set2 = new AnimatorSet(); set2.play(anim2).before(set3) ; set.play(anim).before(set2); set.start();
AnimatorSet set3 = new AnimatorSet(); set3.play(anim4).before(anim3) ; AnimatorSet set2 = new AnimatorSet(); set2.play(anim2).before(set3) ; set.play(anim).before(set2); set.start();这样做的目的是为了,让目标view移动一个来回,从哪里出发, 最后回到出发的位置。
AnimatorSet set = new AnimatorSet() ; ObjectAnimator anim = ObjectAnimator.ofFloat(phone, "alpha", 1f, 0f); anim.setDuration(2000); ObjectAnimator anim2 = ObjectAnimator.ofFloat(phone, "alpha", 0f, 1f); anim2.setDuration(2000); set.play(anim).before(anim2) ; set.start();
AnimatorSet set = new AnimatorSet() ; ObjectAnimator anim = ObjectAnimator .ofFloat(phone, "rotationX", 0f, 180f); anim.setDuration(2000); ObjectAnimator anim2 = ObjectAnimator .ofFloat(phone, "rotationX", 180f, 0f); anim2.setDuration(2000); ObjectAnimator anim3 = ObjectAnimator .ofFloat(phone, "rotationY", 0f, 180f); anim3.setDuration(2000); ObjectAnimator anim4 = ObjectAnimator .ofFloat(phone, "rotationY", 180f, 0f); anim4.setDuration(2000); set.play(anim).before(anim2); set.play(anim3).before(anim4) ; set.start();
set.play(anim).before(anim2); set.play(anim3).before(anim4) ;这样写X和Y会同时旋转
AnimatorSet set = new AnimatorSet() ; ObjectAnimator anim = ObjectAnimator .ofFloat(phone, "scaleX", 1f); anim.setDuration(1000); ObjectAnimator anim2 = ObjectAnimator .ofFloat(phone, "scaleX", 0.5f); anim2.setDuration(1000); ObjectAnimator anim3 = ObjectAnimator .ofFloat(phone, "scaleY", 1f); anim3.setDuration(1000); ObjectAnimator anim4 = ObjectAnimator .ofFloat(phone, "scaleY", 0.5f); anim4.setDuration(1000); ObjectAnimator anim5 = ObjectAnimator .ofFloat(phone, "scaleX", 0.5f); anim5.setDuration(1000); ObjectAnimator anim6 = ObjectAnimator .ofFloat(phone, "scaleX", 1f); anim6.setDuration(1000); ObjectAnimator anim7 = ObjectAnimator .ofFloat(phone, "scaleY",0.5f); anim7.setDuration(1000); ObjectAnimator anim8 = ObjectAnimator .ofFloat(phone, "scaleY", 1f); anim8.setDuration(1000); AnimatorSet set3 = new AnimatorSet() ; set3.play(anim5).before(anim6); AnimatorSet set2 = new AnimatorSet() ; set2.play(anim2).before(set3) ; AnimatorSet set4 = new AnimatorSet() ; set4.play(anim7).before(anim8) ; AnimatorSet set5 = new AnimatorSet() ; set5.play(anim4).before(set4); set.play(anim).before(set2); set.play(anim3).before(set5) ; set.start();