ValueAnimator API 介绍
public class ValueAnimator?
extends?Animator?繼承Animator
| java.lang.Object | ||
| ???? | android.animation.Animator | |
| ? | ???? | android.animation.ValueAnimator |
| ObjectAnimator,?TimeAnimator |
這個類為正在運行的動畫提供了簡單的計時引擎,正在運行的動畫計算動畫的值并且將它設置在目標對象。
所有動畫都使用一個計時脈沖,它運行在自定義的handler去確保屬性的改變放生在UI線程。
默認情況下,ValueAnimator 使用非線性時間插入器,通過AccelerateDecelerateInterpolator類,此類加速進入動畫并且減速退出動畫,這個行為通過調用setInterpolator(TimeInterpolator)來改變。
Animators can be created from either code or resource files. Here is an example of a ValueAnimator resource file:
動畫可以通過代碼或者資源文件創建。一下是一個ValueAnimator 資源文件的例子。
<animator xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:valueFrom="1" android:valueTo="0" android:valueType="floatType" android:repeatCount="1" android:repeatMode="reverse"/>從API23開始,同樣可以用PropertyValuesHolder?和Keyframe?資源標簽去創建多步動畫。注意你可以定義明確的小數值(從0到1)為每一個?keyframe 去決定何時動畫應該到達那個值。當然,你可以停止小數而keyframes 會被均勻地分配在整個過程。
<animator xmlns:android="http://schemas.android.com/apk/res/android"android:duration="1000"android:repeatCount="1"android:repeatMode="reverse"><propertyValuesHolder><keyframe android:fraction="0" android:value="1"/><keyframe android:fraction=".2" android:value=".4"/><keyframe android:fraction="1" android:value="0"/></propertyValuesHolder> </animator>
Summary? 總結
| interface | ValueAnimator.AnimatorUpdateListener Implementors of this interface can add themselves as update listeners to an?ValueAnimatorinstance to receive callbacks on every animation frame, after the current frame's values have been calculated for that?ValueAnimator.? 實現這個接口可以將它們自己添加為對ValueAnimator實例更新監聽,去接收在每一動畫幀的回調,這是發生在當前ValueAnimator幀的值被計算之后。 |
| int | INFINITE This value used used with the?setRepeatCount(int)?property to repeat the animation indefinitely. 這個值用在setRepeatCount(int)?屬性去無限重復動畫。 |
| int | RESTART When the animation reaches the end and?repeatCount?is INFINITE or a positive value, the animation restarts from the beginning. 當動畫結束并且repeatCount? 是INFINITE? ?或者一個正值時,動畫重頭開始。 |
| int | REVERSE When the animation reaches the end and?repeatCount?is INFINITE or a positive value, the animation reverses direction on every iteration. 當動畫結束并且repeatCount? 是INFINITE? ?或者一個正值時,動畫在每個迭代取反方向 |
| ValueAnimator() Creates a new ValueAnimator object. 創建一個新ValueAnimator 對象 |
| void | addUpdateListener(ValueAnimator.AnimatorUpdateListener?listener) Adds a listener to the set of listeners that are sent update events through the life of an animation. 添加一個監聽器到監聽器的集合,這個集合在整個動畫生命周期被發送更新時間 |
| static boolean | areAnimatorsEnabled() Returns whether animators are currently enabled, system-wide. 返回是否動畫當前可操作的 |
| void | cancel() Cancels the animation. 取消動畫 |
| ValueAnimator | clone() Creates and returns a copy of this object. 創建并返回這個對象的副本 |
| void | end() Ends the animation. 結束動畫 |
| float | getAnimatedFraction() Returns the current animation fraction, which is the elapsed/interpolated fraction used in the most recent frame update on the animation. |
| Object | getAnimatedValue() The most recent value calculated by this?ValueAnimator?when there is just one property being animated. ValueAnimator?計算的最近值 當只有一個屬性被執行 |
| Object | getAnimatedValue(String?propertyName) The most recent value calculated by this?ValueAnimator?for?propertyName. 獲取propertyName 對應的ValueAnimator?計算的最近的值 |
| long | getCurrentPlayTime() Gets the current position of the animation in time, which is equal to the current time minus the time that the animation started. 及時獲取當前動畫的位置,相當于當前時間減去開始時間 |
| long | getDuration() Gets the length of the animation. 獲取動畫的時長 |
| static long | getFrameDelay() The amount of time, in milliseconds, between each frame of the animation. 動畫的幀與幀之間時間的總量,毫秒 |
| TimeInterpolator | getInterpolator() Returns the timing interpolator that this ValueAnimator uses. 返回ValueAnimator使用的時間差之器 |
| int | getRepeatCount() Defines how many times the animation should repeat. 返回動畫應該重復的次數 |
| int | getRepeatMode() Defines what this animation should do when it reaches the end. 返回動畫結束時動畫應該做什么 |
| long | getStartDelay() The amount of time, in milliseconds, to delay starting the animation after?start()?is called. ?start()調用之后 延時的時間總量 |
| long | getTotalDuration() Gets the total duration of the animation, accounting for animation sequences, start delay, and repeating. 獲取動畫持續的時間總量,包括順序,開始延時和重復 |
| PropertyValuesHolder[] | getValues() Returns the values that this ValueAnimator animates between. 返回ValueAnimator 所執行在值。 |
| boolean | isRunning() Returns whether this Animator is currently running (having been started and gone past any initial startDelay period and not yet ended). 返回動畫是否在執行。 |
| boolean | isStarted() Returns whether this Animator has been started and not yet ended. 返回是否動畫開始并且還沒結束 |
| static?ValueAnimator | ofArgb(int...?values) Constructs and returns a ValueAnimator that animates between color values. 構造并返回一個執行在顏色之間的ValueAnimator? |
| static?ValueAnimator | ofFloat(float...?values) Constructs and returns a ValueAnimator that animates between float values. 構造并返回一個執行在floate值之間的ValueAnimator? |
| static?ValueAnimator | ofInt(int...?values) Constructs and returns a ValueAnimator that animates between int values. 構造并返回一個執行在int值之間的ValueAnimator? |
| static?ValueAnimator | ofObject(TypeEvaluator?evaluator,?Object...?values) Constructs and returns a ValueAnimator that animates between Object values. 構造并返回一個執行在Object?值之間的ValueAnimator? |
| static?ValueAnimator | ofPropertyValuesHolder(PropertyValuesHolder...?values) Constructs and returns a ValueAnimator that animates between the values specified in the PropertyValuesHolder objects. 構造并返回一個執行在定義在PropertyValuesHolder值之間的ValueAnimator? |
| void | pause() Pauses a running animation. 暫停動畫 |
| void | removeAllUpdateListeners() Removes all listeners from the set listening to frame updates for this animation. 清除所有更新監聽 |
| void | removeUpdateListener(ValueAnimator.AnimatorUpdateListener?listener) Removes a listener from the set listening to frame updates for this animation. 清除集合中的指定監聽 |
| void | resume() Resumes a paused animation, causing the animator to pick up where it left off when it was paused. 使暫停的動畫獲取焦點 |
| void | reverse() Plays the ValueAnimator in reverse. 反向執行動畫 |
| void | setCurrentFraction(float fraction) Sets the position of the animation to the specified fraction. 設置動畫的位置到指定的小數值 |
| void | setCurrentPlayTime(long playTime) Sets the position of the animation to the specified point in time. 設置動畫的位置到指定的時間點 |
| ValueAnimator | setDuration(long duration) Sets the length of the animation. 設置動畫執行的時長 |
| void | setEvaluator(TypeEvaluator?value) The type evaluator to be used when calculating the animated values of this animation. 類型估值器用在計算動畫執行值時 |
| void | setFloatValues(float...?values) Sets float values that will be animated between. 設置動畫執行的值 |
| static void | setFrameDelay(long frameDelay) The amount of time, in milliseconds, between each frame of the animation. 幀與幀之間的時長 |
| void | setIntValues(int...?values) Sets int values that will be animated between. 設置動畫執行的值 |
| void | setInterpolator(TimeInterpolator?value) The time interpolator used in calculating the elapsed fraction of this animation. 設置時間差值器 |
| void | setObjectValues(Object...?values) Sets the values to animate between for this animation. |
| void | setRepeatCount(int value) Sets how many times the animation should be repeated. 設置重復次數 |
| void | setRepeatMode(int value) Defines what this animation should do when it reaches the end. 設置動畫結束時的動作 |
| void | setStartDelay(long startDelay) The amount of time, in milliseconds, to delay starting the animation after?start()?is called. 設置開始延時 |
| void | setValues(PropertyValuesHolder...?values) Sets the values, per property, being animated between. |
| void | start() Starts this animation. |
| String | toString() Returns a string representation of the object. |
總結
以上是生活随笔為你收集整理的ValueAnimator API 介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Animatable API介绍
- 下一篇: Java 面向对象四大特性