- Android自带的插值器
- 自定义插值器
- 插值器常用到工具
1. Android自带的插值器
下图为Android自带的所有插值器,用法为android:interpolator="@android:interpolator/cycle"
cycle是插值器的名称
详细介绍:
插值器java类 | 介绍 | 对应的资源文件 |
---|---|---|
AccelerateDecelerateInterpolator | 开始慢然后加速最后再减速 ,使用 | @android:interpolator/accelerate_decelerate |
AccelerateInterpolator | 开始缓慢然后一直加速 | @android:interpolator/accelerate_quad |
AnticipateInterpolator | 先向后 然后再向前 | @android:interpolator/anticipate |
AnticipateOvershootInterpolator | 先向后 然后向前并且超过目标点 然后再回到目标点 | @android:interpolator/anticipate_overshoot |
BounceInterpolator | 最后会反弹的插值器 | @android:interpolator/bounce |
CycleInterpolator | 重复的插值器,其速率像正弦曲线 | @android:interpolator/cycle |
DecelerateInterpolator | 开始速率很快 然后一直减速 | @android:interpolator/decelerate_quad |
LinearInterpolator | 匀速插值器 | @android:interpolator/linear |
OvershootInterpolator | 向前移动并超过目标值,最后再返回到目标点 | @android:interpolator/overshoot |
PathInterpolator | 路径插值器 慢进快出 | @android:interpolator/fast_out_slow_in |
PathInterpolator | 路径插值器 匀速进快速出 | @android:interpolator/fast_out_linear_in |
PathInterpolator | 路径插值器 慢进匀速出 | @android:interpolator/linear_out_slow_in |
2. 自定义插值器
自定义插值器 需要继承Interpolator接口,实现`float getInterpolation(float input); 方法
如:
public class MyInterpolator implements Interpolator {
@Override
public float getInterpolation(float input) {
return 2*input;
}
}
使用:不过需要注意的一点就是自定义的插值器不能使用xml来设置,只能通过java代码来设置如下
AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f,0f);
alphaAnimation.setInterpolator(new MyInterpolator());
3. 插值器常用到工具
我们在自定义插值器的时候,有时可能无法及时的看到起效果,那么这时就需要一些工具来帮助我们了.