旋转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;
}
Logo

助力广东及东莞地区开发者,代码托管、在线学习与竞赛、技术交流与分享、资源共享、职业发展,成为松山湖开发者首选的工作与学习平台

更多推荐