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