做过android动画的人对Interpolator应该不会陌生,这个类主要是用来控制android动画的执行速率,一般情况下,如果我们不设置,动画都不是匀速执行的,系统默认是先加速后减速这样一种动画执行速率。
android通过Interpolator类来让我们自己控制动画的执行速率,还记得上一篇博客中我们使用属性动画实现的旋转效果吗?在不设置Interpolator的情况下,这个动画是先加速后减速,我们现在使用android系统提供的类LinearInterpolator来设置动画的执行速率,LinearInterpolator可以让这个动画匀速执行,我们来看一个案例,我们有两个TextView重叠放在一起,点击旋转按钮后这两个TextView同时执行旋转动画,不同的是一个设置了LinearInterpolator,而另外一个什么都没有设置,代码如下:LinearInterpolator ll = new LinearInterpolator();
ObjectAnimator animator = ObjectAnimator.ofFloat(tv, "rotation", 0f, 360f);
animator.setInterpolator(ll);
animator.setDuration(5000);
animator.start();
ObjectAnimator animator2 = ObjectAnimator.ofFloat(tv2, "rotation", 0f, 360f);
animator2.setDuration(5000);
animator2.start(