バウンスしたい円があるので、幅を広げて高さを縮め、逆にして同じことを数回繰り返します。これはすべて、続けていくつかの ScaleAnimations で機能します。問題は、pivotY をビューの一番下にしたいということです。この場合、新しいアニメーションが開始されるたびに、ピボット ポイントが中心にリセットされます。これが私のコードです:
bounceAnimationPartOne = new ScaleAnimation(1.0f, 1.0f, 1.62f, 0.62f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1.0f);
bounceAnimationPartOne.setDuration(45);
bounceAnimationPartOne.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
view.startAnimation(bounceAnimationPartTwo);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
bounceAnimationPartTwo = new ScaleAnimation(1.62f, 0.62f, 0.76f, 1.3f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1.0f);
bounceAnimationPartTwo.setDuration(90);
bounceAnimationPartTwo.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
view.startAnimation(bounceAnimationPartThree);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
bounceAnimationPartThree = new ScaleAnimation(0.76f, 1.3f, 1.23f, 0.81f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1.0f);
bounceAnimationPartThree.setDuration(105);
bounceAnimationPartThree.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
view.startAnimation(bounceAnimationPartFour);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
bounceAnimationPartFour = new ScaleAnimation(1.23f, 0.81f, 1.0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1.0f);
bounceAnimationPartFour.setDuration(60);