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;
}