旋转180度
Animation anim =new RotateAnimation(0f, 180f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setFillAfter(true); // 设置保持动画最后的状态
anim.setDuration(500); // 设置动画时间
anim.setInterpolator(new AccelerateInterpolator()); // 设置插入器
anim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
Log.i("lgq", "re==logtest===onAnimationStart==");
}
@Override
public void onAnimationEnd(Animation animation) {
Log.i("lgq", "re==logtest===onAnimationEnd==" );
}
@Override
public void onAnimationRepeat(Animation animation) {
Log.i("lgq", "re==logtest===onAnimationRepeat==");
}
});
localstatusfreeview.startAnimation(anim);
反转180度
Animation anim =new RotateAnimation(180f, 0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setFillAfter(true); // 设置保持动画最后的状态
anim.setDuration(500); // 设置动画时间
anim.setInterpolator(new AccelerateInterpolator()); // 设置插入器
localstatusfreeview.startAnimation(anim);
2、 圆形图片循环旋转动画
private ObjectAnimator mObjectAnimator; private long mCurrentPlayTime; private boolean ifop=true; public static int rotationTime = 20000;
/**
* 设置旋转的动画
*/
public void setAnimation() {
if (mObjectAnimator == null) {
mObjectAnimator = ObjectAnimator.ofFloat(tvHobby, "rotation", 0, 360);
mObjectAnimator.setDuration(rotationTime);
mObjectAnimator.setInterpolator(new LinearInterpolator());
mObjectAnimator.setRepeatCount(ValueAnimator.INFINITE);
}
startAnimation();
}
/**
* 暂停旋转
*/
private void stopAnimation() {
mCurrentPlayTime = mObjectAnimator.getCurrentPlayTime();
mObjectAnimator.cancel();
}
/**
* 开始旋转
*/
private void startAnimation() {
mObjectAnimator.start();
mObjectAnimator.setCurrentPlayTime(mCurrentPlayTime);
}
附:开启暂停
if (ifop) {
stopAnimation();
ifop = !ifop;
} else {
startAnimation();
ifop = !ifop;
}
本文介绍了如何使用Android中的RotateAnimation实现视图的180度旋转效果,并提供了创建一个循环旋转动画的方法,包括动画的启动与暂停逻辑。

被折叠的 条评论
为什么被折叠?



