2012年8月25日 星期六

[Animation] Property Animation (>= 11)

Supported from API Level 11.

Property Animation
  • A property animation changes a property's (a field in an object) value over a specified length of time.
  • 以某項 attribute 進行動畫。ex: x-axis 使物件橫向移動。
  • 分為兩部份:
    • 計算產生動畫的值。
    • 設定動畫值於物件的 property 中。

  • The view animation system
    • View animation 是藉由重繪 view 來顯示動畫,而此動作是由每個 view 自己的 container 來做(because the View itself had no properties to manipulate)。
    • 雖然結果可以看到 view 出現在不同位置,但實際上沒有改變到 view object 的任何 property,所以關於 view object 的設定卻還停留在原位 (ex: 點擊原始位置才會觸發 view 的事件)。
  • The property animation system
    • Property animation 則是改善了這個問題,因為它是改變 view object 的 property 來顯示動畫。
    • 而當 view object 的 property 改變,會自動呼叫 invalidate() 。

TypeEvaluator
  • 決定如何去計算進行動畫的 attribute 的值。
  • An interface that allows you to create your own evaluator.
  • If you are animating an object property that is not an int, float, or color, you must implement the TypeEvaluator interface to specify how to compute the object property's animated values.
  • You can also specify a custom TypeEvaluator for int, float, and color values as well, if you want to process those types differently than the default behavior.

ValueAnimator
  • Keeps track of your animation's timing.
  • How long the animation has been running.
  • The current value of the property that it is animating.
  • 管理 object 動畫中的 attribute 在動畫過程中的值,包含資訊:
    • 是否重複動畫。
    • 接收更新動作通知的 listeners。
    • 使用客制化的 evaluator。
  • 但 ValueAnimator 並不會將計算後的值設給 property,因此要使用 listeners 接收計算後的值再自行去更新,例如需實作 ValueAnimator.AnimatorUpdateListener

ObjectAnimator
  • A subclass of ValueAnimator.
  • 可以設定發生動畫的物件以及決定動畫內容的 property。
  • 此 class 會更新 property 的值,所以大部份使用此 class 比較方便,不需自行處理更新這部份動作。

AnimatorSet
  • 設定動畫效果於一群 view,他們能一起變化、有序的或是延遲的。
  • Provides a mechanism to group animations together so that they run in relation to one another. You can set animations to play together, sequentially, or after a specified delay.


* Reference
- Property Animation | Android Developers

沒有留言:

張貼留言