Android Animation --- 无限360度旋转

  • 做过重复360度旋转的就知道,到达终点是略有卡顿/停顿

查看Animation.java源码

    /**
     * Gurantees that this animation has an interpolator. Will use
     * a AccelerateDecelerateInterpolator is nothing else was specified.
     */
    protected void ensureInterpolator() {
        if (mInterpolator == null) {
            mInterpolator = new AccelerateDecelerateInterpolator();
        }
    }

发现默认使用的是加速插补器,所以到达终点出现卡顿/停顿,就是它导致的,更改为匀速的插补器即可

代码如下:

ObjectAnimator rotation = ObjectAnimator.ofFloat(hwLogoTurn, "rotation", 0f, 359f);//最好是0f到359f,0f和360f的位置是重复的

rotation.setRepeatCount(ObjectAnimator.INFINITE);
rotation.setInterpolator(new LinearInterpolator());
rotation.setDuration(5000);
rotation.start();

现在可以优哉游哉的跑了

你可能感兴趣的:(Android,Android,Animation)