Android 动画以view中心点旋转动画

旋转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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值