3.属性动画:3.0之前只有view动画和帧动画,这两种动画只改变view的视觉效果,对其属性无影响。所以加入了属性动画。
在动画持续时间内,通过不断对值进行改变,并不断将该值赋给对象,从而实现该对象在任意属性上的动画效果。
利用属性动画组合实现view动画的四种操作。
//propertyAnimationTest
public void animatorSet(View view) {
// 顺序执行
AnimatorSet set1 = new AnimatorSet();
ObjectAnimator translationAnimator1 = ObjectAnimator.ofFloat(view, "translationX", -400);
ObjectAnimator translationAnimator2 = ObjectAnimator.ofFloat(view, "translationY", 400);
ObjectAnimator translationAnimator3 = ObjectAnimator.ofFloat(view, "translationX", 300);
ObjectAnimator translationAnimator4 = ObjectAnimator.ofFloat(view, "translationY", 0);
ObjectAnimator translationAnimator5 = ObjectAnimator.ofFloat(view, "translationX", 0);
set1.playSequentially(translationAnimator1, translationAnimator2, translationAnimator3, translationAnimator4, translationAnimator5);
// 设置动画时长,这里的时长是每个子动画的时长
set1.setDuration(5000);
// 同时执行
AnimatorSet set2 = new AnimatorSet();
ObjectAnimator rotationAnimator = ObjectAnimator.ofFloat(view, "rotationY", 0, 360);
ObjectAnimator scaleAnimator1 = ObjectAnimator.ofFloat(view, "scaleX", 0.2f, 1);
ObjectAnimator scaleAnimator2 = ObjectAnimator.ofFloat(view, "scaleY", 0.2f, 1);
ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(view, "alpha", 0.2f, 1);
set2.playTogether(rotationAnimator, scaleAnimator1, scaleAnimator2, alphaAnimator);
// 设置动画时长,这里的时长是每个子动画的时长
set2.setDuration(5000);
AnimatorSet set = new AnimatorSet();
set.playTogether(set1,set2);
set.start();
}
//属性动画
slide_view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
animatorSet(slide_view);
}
});
动画效果: