【转载】Animation 动画(二)Interpolator插值器

转自 http://blog.csdn.net/harvic880925/article/details/40049763

  • AccelerateDecelerateInterpolator   在动画开始与介绍的地方速率改变比较慢,在中间的时候加速
  • AccelerateInterpolator                     在动画开始的地方速率改变比较慢,然后开始加速
  • AnticipateInterpolator                      开始的时候向后然后向前甩
  • AnticipateOvershootInterpolator     开始的时候向后然后向前甩一定值后返回最后的值
  • BounceInterpolator                          动画结束的时候弹起
  • CycleInterpolator                             动画循环播放特定的次数,速率改变沿着正弦曲线
  • DecelerateInterpolator                    在动画开始的地方快然后慢
  • LinearInterpolator                            以常量速率改变
  • OvershootInterpolator                      向前甩一定值后再回到原来位置

下面先看看Scale标签应用插值器后,都会变成什么样。

先看下XML代码:(从控件中心点,从0放大到1.4倍,保持结束时的状态)

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <scale xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:interpolator="@android:anim/accelerate_decelerate_interpolator"  
  4.     android:fromXScale="0.0"  
  5.     android:toXScale="1.4"  
  6.     android:fromYScale="0.0"  
  7.     android:toYScale="1.4"  
  8.     android:pivotX="50%"  
  9.     android:pivotY="50%"  
  10.     android:duration="700"   
  11.     android:fillAfter="true"  
  12. />  
下面一个个看看,每个xml值对应的scale动画是怎样的。

AccelerateDecelerateInterpolator 在动画开始与介绍的地方速率改变比较慢,在中间的时候加速


                   AccelerateInterpolator                                                 DecelerateInterpolator                    

在动画开始的地方速率改变比较慢,然后开始加速                   在动画开始的地方快然后慢

【转载】Animation 动画(二)Interpolator插值器_第1张图片     【转载】Animation 动画(二)Interpolator插值器_第2张图片

            AnticipateInterpolator                                            AnticipateOvershootInterpolator 

      开始的时候向后然后向前甩                                开始的时候向后然后向前甩一定值后返回最后的值

【转载】Animation 动画(二)Interpolator插值器_第3张图片   【转载】Animation 动画(二)Interpolator插值器_第4张图片

             BounceInterpolator                                                      CycleInterpolator       

            动画结束的时候弹起                             动画循环播放特定的次数,速率改变沿着正弦曲线

【转载】Animation 动画(二)Interpolator插值器_第5张图片   【转载】Animation 动画(二)Interpolator插值器_第6张图片

                        LinearInterpolator                                  OvershootInterpolator  

                      以常量速率改变                                向前甩一定值后再回到原来位置

【转载】Animation 动画(二)Interpolator插值器_第7张图片   【转载】Animation 动画(二)Interpolator插值器_第8张图片


Interpolater插值器---代码生成

插值器XML属性及对应的类如下表所示:

Interpolator class Resource ID
AccelerateDecelerateInterpolator @android:anim/accelerate_decelerate_interpolator
AccelerateInterpolator @android:anim/accelerate_interpolator
AnticipateInterpolator @android:anim/anticipate_interpolator
AnticipateOvershootInterpolator @android:anim/anticipate_overshoot_interpolator
BounceInterpolator @android:anim/bounce_interpolator
CycleInterpolator @android:anim/cycle_interpolator
DecelerateInterpolator @android:anim/decelerate_interpolator
LinearInterpolator @android:anim/linear_interpolator
OvershootInterpolator @android:anim/overshoot_interpolator

使用方法:(为sacleAnimation增加bounce插值器)

  1. ScaleAnimation interpolateScaleAnim=new ScaleAnimation(0.0f,1.4f,0.0f,1.4f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);  
  2. interpolateScaleAnim.setInterpolator(new BounceInterpolator());  
  3. interpolateScaleAnim.setDuration(3000);  
【转载】Animation 动画(二)Interpolator插值器_第9张图片    【转载】Animation 动画(二)Interpolator插值器_第10张图片

你可能感兴趣的:(【转载】Animation 动画(二)Interpolator插值器)