您的位置:首页 > 移动开发 > Android开发

Android之动画解析

2016-01-11 23:28 477 查看
extends
Animator

类概述

这个类提供了一个用于计算动画值并将其设置为目标对象的动画的简单时序引擎。

有一个单一的定时脉冲,所有动画使用。它运行在一个自定义处理程序中,以确保用户界面线程中的属性发生更改。

默认情况下,ValueAnimator采用非线性时域插值,通过AccelerateDecelerateInterpolator类,加速和减速的动画。这种行为可以通过调用setinterpolator改变(timeinterpolator)。

动画师可以创建代码或资源文件。这里是一个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"/>
它也可以结合使用PropertyValuesHolder和帧标签来创建一个多步骤的动画资源。请注意,您可以指定明确的分数值(从0到1)为每个关键帧来确定时,在整个时间,动画应该到达那个值。或者,你可以把分数和关键帧将在总时间平均分配

<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>
Nested Classes

interfaceValueAnimator.AnimatorUpdateListenerImplementors of this interface can add themselves as update listeners to an
ValueAnimator
instance to receive callbacks on every animation frame, after the current frame's values have been calculated for that
ValueAnimator
Constants

intINFINITEThis value used used with the
setRepeatCount(int)
property to repeat the
animation indefinitely.   这个值用来与setrepeatcount(int)属性重复动画无限期。           
intRESTARTWhen the animation reaches the end and
repeatCount
is INFINITE or a positive value, the animation restarts from the beginning.                          
intREVERSEWhen the animation reaches the end and
repeatCount
is INFINITE or a positive value, the animation reverses direction on every iteration. 逆转
Public Constructors
ValueAnimator()

Creates a new ValueAnimator object.  创建一个新的ValueAnimator对象。
Public Methods:

voidaddUpdateListener(ValueAnimator.AnimatorUpdateListener
listener)Adds a listener to the set of listeners that are sent update events through the life of an animation.
voidcancel()Cancels the animation.取消动画。
ValueAnimatorclone()Creates and returns a copy of this
Object
.创建并返回该对象的副本。
voidend()Ends the animation.结束动画。
floatgetAnimatedFraction()Returns the current animation fraction, which is the elapsed/interpolated fraction used in the most recent frame update on the animation.
Object4000
getAnimatedValue()The most recent value calculated by this
ValueAnimator
when there is just one property being animated.
ObjectgetAnimatedValue(String
propertyName)The most recent value calculated by this
ValueAnimator
for
propertyName
.

longgetCurrentPlayTime()Gets the current position of the animation in time, which is equal to the current time minus the time that the animation started.获取当前播放时间
longgetDuration()Gets the length of the animation.获取动画长度。
static longgetFrameDelay()The amount of time, in milliseconds, between each frame of the animation.每一帧的之间的时间
TimeInterpolatorgetInterpolator()Returns the timing interpolator that this ValueAnimator uses.返回定时插补
intgetRepeatCount()Defines how many times the animation should repeat.获取动画重复的次数
intgetRepeatMode()Defines what this animation should do when it reaches the end.
longgetStartDelay()The amount of time, in milliseconds, to delay starting the animation after
start()

is called.延迟多少毫米开始
PropertyValuesHolder[]getValues()Returns the values that this ValueAnimator animates between.
booleanisRunning()Returns whether this Animator is currently running (having been started and gone past any initial startDelay period and not yet ended).
booleanisStarted()Returns whether this Animator has been started and not yet ended.
staticValueAnimatorofArgb(int... values)Constructs and returns a ValueAnimator that animates between color values.
staticValueAnimatorofFloat(float... values)Constructs and returns a ValueAnimator that animates between float values.
staticValueAnimatorofInt(int... values)Constructs and returns a ValueAnimator that animates between int values.
staticValueAnimatorofObject(TypeEvaluator
evaluator,
Object... values)Constructs and returns a ValueAnimator that animates between Object values.
staticValueAnimatorofPropertyValuesHolder(PropertyValuesHolder...
values)Constructs and returns a ValueAnimator that animates between the values specified in the PropertyValuesHolder objects.
voidpause()Pauses a running animation.
voidremoveAllUpdateListeners()Removes all listeners from the set listening to frame updates for this animation.
voidremoveUpdateListener(ValueAnimator.AnimatorUpdateListener
listener)Removes a listener from the set listening to frame updates for this animation.
voidresume()Resumes a paused animation, causing the animator to pick up where it left off when it was paused.
voidreverse()Plays the ValueAnimator in reverse.
voidsetCurrentFraction(float
fraction)Sets the position of the animation to the specified fraction.
voidsetCurrentPlayTime(long
playTime)Sets the position of the animation to the specified point in time.
ValueAnimatorsetDuration(long duration)Sets the length of the animation.
voidsetEvaluator(TypeEvaluator
value)The type evaluator to be used when calculating the animated values of this animation.
voidsetFloatValues(float...
values)Sets float values that will be animated between.
static voidsetFrameDelay(long frameDelay)The amount of time, in milliseconds, between each frame of the animation.
voidsetIntValues(int...
values)Sets int values that will be animated between.
voidsetInterpolator(TimeInterpolator
value)The time interpolator used in calculating the elapsed fraction of this animation.
voidsetObjectValues(Object...
values)Sets the values to animate between for this animation.
voidsetRepeatCount(int value)Sets how many times the animation should be repeated.
voidsetRepeatMode(int value)Defines what this animation should do when it reaches the end.
voidsetStartDelay(long startDelay)The amount of time, in milliseconds, to delay starting the animation after
start()

is called.
voidsetValues(PropertyValuesHolder...
values)Sets the values, per property, being animated between.
voidstart()Starts this animation.
StringtoString()Returns a string containing a concise, human-readable description of this object.                          
更详细的内容请参考http://blog.csdn.net/guolin_blog/article/details/43536355
http://blog.csdn.net/guolin_blog/article/details/43816093 http://blog.csdn.net/guolin_blog/article/details/44171115
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: