1、直线运动:
////1、多个同步 、异步、顺序执行
ObjectAnimator animator1 = ObjectAnimator.ofFloat(imageView,
"translationX", 0F, 360F);// X轴平移旋转
ObjectAnimator animator2 = ObjectAnimator.ofFloat(imageView,
"translationY", 0F, 300F);// Y轴平移旋转
ObjectAnimator animator3 = ObjectAnimator.ofFloat(imageView,
"rotation", 0F, 360F);// 360度旋转
AnimatorSet set = new AnimatorSet();
// set.playSequentially(animator1, animator2, animator3);// 分步执行
set.playTogether(animator1, animator2, animator3);// 同步执行
// 属性动画的执行顺序控制
// 先同步执行动画animator2和animator3,然后再执行animator1
/*
* set.play(animator3).with(animator1);
*
* set.play(animator2).after(animator3);
*/
set.setDuration(1000);
set.start();
2、抛物线运动:
// 分300步进行移动动画
final int count = 150;
/**
* 要start 动画的那张图片的ImageView--------------------(二)抛物线运动
*
* @param imageView
*/
private void startAnimation(final ImageView imageView) {
Keyframe[] keyframes = new Keyframe[count];
final float keyStep = 1f / (float) count;
float key = keyStep;
for (int i = 0; i < count; ++i) {
keyframes[i] = Keyframe.ofFloat(key, i + 1);
key += keyStep;
}
PropertyValuesHolder pvhX = PropertyValuesHolder.ofKeyframe(
"translationX", keyframes);
key = keyStep;
for (int i = 0; i < count; ++i) {
keyframes[i] = Keyframe.ofFloat(key, -getY(i + 1));
key += keyStep;
}
PropertyValuesHolder pvhY = PropertyValuesHolder.ofKeyframe(
"translationY", keyframes);
ObjectAnimator animator3 = ObjectAnimator.ofFloat(imageView,
"rotation", 0F, 360F);// 360度旋转
ObjectAnimator yxBouncer = ObjectAnimator.ofPropertyValuesHolder(imageView, pvhY, pvhX).setDuration(1500);
yxBouncer.setInterpolator(new BounceInterpolator());
AnimatorSet set = new AnimatorSet();
// set.playSequentially(animator1, animator2, animator3);// 分步执行
set.playTogether(yxBouncer, animator3);// 同步执行
set.setDuration(1000);
set.start();
}
final float a = -1f / 105f;
/**
* 这里是根据三个坐标点{(0,0),(300,0),(150,300)}计算出来的抛物线方程
*
* @param x
* @return
*/
private float getY(float x) {
return a * x * x + 4 * x;
}