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

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;
    }

推荐阅读更多精彩内容