美文网首页
属性动画1(无限循环匀速转动的风扇)

属性动画1(无限循环匀速转动的风扇)

作者: 饥人谷_js_chen | 来源:发表于2017-11-14 21:23 被阅读0次

1.难点:

  • 无限循环:

ObjectAnimation.setRepeatCount(ValueAnimator.INFINITE);

  • 匀速转动

ObjectAnimation.setInterpolator(new LinearInterpolator());

2.代码:

public static ObjectAnimator getRotateAnimation(View pView, boolean isClockWise, long duration, boolean isRepeat) {
        int endAngle;
        if (isClockWise) {
            endAngle = 360;
        } else {
            endAngle = -360;
        }
        ObjectAnimator res = ObjectAnimator.ofFloat(pView, "rotation", 0, endAngle);
        res.setDuration(duration);
        res.setInterpolator(new LinearInterpolator());
        if (isRepeat) {
            res.setRepeatCount(ValueAnimator.INFINITE);
        }
        return res;
    }

相关文章

网友评论

      本文标题:属性动画1(无限循环匀速转动的风扇)

      本文链接:https://www.haomeiwen.com/subject/wvcqvxtx.html