实现方式一:
ObjectAnimator catAnimation = ObjectAnimator.ofFloat(catIv, "rotationY", 0f, 360f);
catAnimation.setDuration(1000);
catAnimation.setInterpolator(new LinearInterpolator());
catAnimation.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
catAnimation.start();
动画后还原: 1:
AnimatorSet animatorSet = new AnimatorSet();
ObjectAnimator animator = ObjectAnimator.ofFloat(catIv, "rotationY", 180f, 0f);
animator.setDuration(0);
animatorSet.playSequentially(catAnimation,animator);
animatorSet.start();
2:
catIv.setRotationY(0);
实现方式二:
int centerX = catIv.getWidth() / 2;
int centerY = catIv.getHeight() / 2;
Rotate3dAnimation rotate3dAnimation = new Rotate3dAnimation(0f, 180f, centerX, centerY, 0, false);
rotate3dAnimation.setDuration(1000);
rotate3dAnimation.setFillBefore(true);
catIv.startAnimation(rotate3dAnimation);
动画后还原:
rotate3dAnimation.setFillBefore(true);