类/接口 描述
AccelerateDecelerateInterpolator 一种插值器,其变化率开始和结束缓慢,但在中间加速
AccelerateInterpolator 一种插值器,其变化率开始缓慢然后加速
AnticipateInterpolator 一个插值器,其变化开始向后然后向前抛出
AnticipateOvershootInterpolator 一个插值器,其变化开始向后,向前抛出并超过目标值,然后最终回到最终值
BounceInterpolator 一个插值器,其变化在最后反弹
CycleInterpolator 一个插值器,其动画重复指定的周期数
DecelerateInterpolator 一个插值器,它的变化率开始很快然后减速
LinearInterpolator 变化率恒定的插值器。
OvershootInterpolator 一个插值器,其变化向前抛出并超过最后一个值,然后返回
TimeInterpolator 一个允许您实现自己的插值器的接口。

自定义插值器 - 实现 TimeInterpolator 接口

  1. // TimeInterpolator接口
  2. public interface TimeInterpolator {
  3. // 参数说明
  4. // input值值变化范围是0-1,且随着动画进度(0% - 100% )均匀变化
  5. // 即动画开始时,input值 = 0;动画结束时input = 1
  6. // 而中间的值则是随着动画的进度(0% - 100%)在0到1之间均匀增加
  7. float getInterpolation(float input);
  8. }
  9. // Interpolator接口
  10. public interface Interpolator extends TimeInterpolator {
  11. }
  1. public class MyInterpolator implements TimeInterpolator {
  2. @Override
  3. public float getInterpolation(float input) {
  4. float result;
  5. if (input <= 0.5) {
  6. result = (float) (Math.sin(Math.PI * input)) / 2;
  7. // 使用正弦函数来实现先减速后加速的功能,逻辑如下:
  8. // 因为正弦函数初始弧度变化值非常大,刚好和余弦函数是相反的
  9. // 随着弧度的增加,正弦函数的变化值也会逐渐变小,这样也就实现了减速的效果。
  10. // 当弧度大于π/2之后,整个过程相反了过来,现在正弦函数的弧度变化值非常小,渐渐随着弧度继续增加,变化值越来越大,弧度到π时结束,这样从0过度到π,也就实现了先减速后加速的效果
  11. } else {
  12. result = (float) (2 - Math.sin(Math.PI * input)) / 2;
  13. }
  14. return result;
  15. // 返回的result值 = 随着动画进度呈先减速后加速的变化趋势
  16. }
  17. }