自定义控件(31)---【转载】Animation 动画(二)Interpolator插值器

来源:互联网 发布:软件 需求分析 文档 编辑:程序博客网 时间:2024/06/05 08:22

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

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

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

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

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  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                    

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

     

            AnticipateInterpolator                                            AnticipateOvershootInterpolator 

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

   

             BounceInterpolator                                                      CycleInterpolator       

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

   

                        LinearInterpolator                                  OvershootInterpolator  

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

   


Interpolater插值器---代码生成

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

Interpolator classResource IDAccelerateDecelerateInterpolator@android:anim/accelerate_decelerate_interpolatorAccelerateInterpolator@android:anim/accelerate_interpolatorAnticipateInterpolator@android:anim/anticipate_interpolatorAnticipateOvershootInterpolator@android:anim/anticipate_overshoot_interpolatorBounceInterpolator@android:anim/bounce_interpolatorCycleInterpolator@android:anim/cycle_interpolatorDecelerateInterpolator@android:anim/decelerate_interpolatorLinearInterpolator@android:anim/linear_interpolatorOvershootInterpolator@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);  
   

0 0
原创粉丝点击