interpolator

 
1.  <?xml  version="1.0"  encoding="utf-8"?>     
2.  <set   
3.  xmlns:Android="http://schemas.android.com/apk/res/android"   
4.  Android:interpolator="@android:anim/decelerate_interpolator"> 
<scale  Android:fromXScale="2.0"  android:toXScale="1.0"     
5.  Android:fromYScale="2.0"  android:toYScale="1.0"     
6.  Android:pivotX="50%p"  android:pivotY="50%p"     
7.  Android:duration="@android:integer/config_mediumAnimTime"  /> 
</set>     
可能有很多人不理解其中的android:interpolator="@android:anim/decelerate_interpolator"是什麼含義,文檔裏說的也不太清楚,其實很簡單,看下面:
      interpolator定義一個動畫的變化率(the rate of change)。這使得基本的動畫效果(alpha, scale, translate, rotate)得以加速,減速,重複等。

用通俗的一點的話理解就是:動畫的進度使用 Interpolator 控制。Interpolator 定義了動畫的變化速度,可以實現勻速、正加速、負加速、無規則變加速等。Interpolator 是基類,封裝了所有 Interpolator 的共同方法,它只有一個方法,即 getInterpolation (float input),該方法 maps a point on the timeline to a multiplier to be applied to the transformations of an animation。Android 提供了幾個 Interpolator 子類,實現了不同的速度曲線,如下:

AccelerateDecelerateInterpolator        在動畫開始與介紹的地方速率改變比較慢,在中間的時侯加速
AccelerateInterpolator        在動畫開始的地方速率改變比較慢,然後開始加速
CycleInterpolator        動畫循環播放特定的次數,速率改變沿着正弦曲線
DecelerateInterpolator        在動畫開始的地方速率改變比較慢,然後開始減速
LinearInterpolator        在動畫的以均勻的速率改變
對於 LinearInterpolator ,變化率是個常數,即 f (x) = x.
public float getInterpolation(float input) {
return input;
}
Interpolator其他的幾個子類,也都是按照特定的算法,實現了對變化率。還可以定義自己的 Interpolator 子類,實現拋物線、自由落體等物理效果。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章