FileDocCategorySizeDatePackage
Keyframe.javaAPI DocAndroid 5.1 API14755Thu Mar 12 22:22:08 GMT 2015android.animation

Keyframe

public abstract class Keyframe extends Object implements Cloneable
This class holds a time/value pair for an animation. The Keyframe class is used by {@link ValueAnimator} to define the values that the animation target will have over the course of the animation. As the time proceeds from one keyframe to the other, the value of the target object will animate between the value at the previous keyframe and the value at the next keyframe. Each keyframe also holds an optional {@link TimeInterpolator} object, which defines the time interpolation over the intervalue preceding the keyframe.

The Keyframe class itself is abstract. The type-specific factory methods will return a subclass of Keyframe specific to the type of value being stored. This is done to improve performance when dealing with the most common cases (e.g., float and int values). Other types will fall into a more general Keyframe class that treats its values as Objects. Unless your animation requires dealing with a custom type or a data structure that needs to be animated directly (and evaluated using an implementation of {@link TypeEvaluator}), you should stick to using float and int as animations using those types have lower runtime overhead than other types.

Fields Summary
boolean
mHasValue
Flag to indicate whether this keyframe has a valid value. This flag is used when an animation first starts, to populate placeholder keyframes with real values derived from the target object.
boolean
mValueWasSetOnStart
Flag to indicate whether the value in the keyframe was read from the target object or not. If so, its value will be recalculated if target changes.
float
mFraction
The time at which mValue will hold true.
Class
mValueType
The type of the value in this Keyframe. This type is determined at construction time, based on the type of the value object passed into the constructor.
private TimeInterpolator
mInterpolator
The optional time interpolator for the interval preceding this keyframe. A null interpolator (the default) results in linear interpolation over the interval.
Constructors Summary
Methods Summary
public abstract android.animation.Keyframeclone()

public floatgetFraction()
Gets the time for this keyframe, as a fraction of the overall animation duration.

return
The time associated with this keyframe, as a fraction of the overall animation duration. This should be a value between 0 and 1.

        return mFraction;
    
public TimeInterpolatorgetInterpolator()
Gets the optional interpolator for this Keyframe. A value of null indicates that there is no interpolation, which is the same as linear interpolation.

return
The optional interpolator for this Keyframe.

        return mInterpolator;
    
public java.lang.ClassgetType()
Gets the type of keyframe. This information is used by ValueAnimator to determine the type of {@link TypeEvaluator} to use when calculating values between keyframes. The type is based on the type of Keyframe created.

return
The type of the value stored in the Keyframe.

        return mValueType;
    
public abstract java.lang.ObjectgetValue()
Gets the value for this Keyframe.

return
The value for this Keyframe.

public booleanhasValue()
Indicates whether this keyframe has a valid value. This method is called internally when an {@link ObjectAnimator} first starts; keyframes without values are assigned values at that time by deriving the value for the property from the target object.

return
boolean Whether this object has a value assigned.

        return mHasValue;
    
public static android.animation.KeyframeofFloat(float fraction, float value)
Constructs a Keyframe object with the given time and value. The time defines the time, as a proportion of an overall animation's duration, at which the value will hold true for the animation. The value for the animation between keyframes will be calculated as an interpolation between the values at those keyframes.

param
fraction The time, expressed as a value between 0 and 1, representing the fraction of time elapsed of the overall animation duration.
param
value The value that the object will animate to as the animation time approaches the time in this keyframe, and the the value animated from as the time passes the time in this keyframe.

        return new FloatKeyframe(fraction, value);
    
public static android.animation.KeyframeofFloat(float fraction)
Constructs a Keyframe object with the given time. The value at this time will be derived from the target object when the animation first starts (note that this implies that keyframes with no initial value must be used as part of an {@link ObjectAnimator}). The time defines the time, as a proportion of an overall animation's duration, at which the value will hold true for the animation. The value for the animation between keyframes will be calculated as an interpolation between the values at those keyframes.

param
fraction The time, expressed as a value between 0 and 1, representing the fraction of time elapsed of the overall animation duration.

        return new FloatKeyframe(fraction);
    
public static android.animation.KeyframeofInt(float fraction, int value)
Constructs a Keyframe object with the given time and value. The time defines the time, as a proportion of an overall animation's duration, at which the value will hold true for the animation. The value for the animation between keyframes will be calculated as an interpolation between the values at those keyframes.

param
fraction The time, expressed as a value between 0 and 1, representing the fraction of time elapsed of the overall animation duration.
param
value The value that the object will animate to as the animation time approaches the time in this keyframe, and the the value animated from as the time passes the time in this keyframe.




                                                                                                                       
           
        return new IntKeyframe(fraction, value);
    
public static android.animation.KeyframeofInt(float fraction)
Constructs a Keyframe object with the given time. The value at this time will be derived from the target object when the animation first starts (note that this implies that keyframes with no initial value must be used as part of an {@link ObjectAnimator}). The time defines the time, as a proportion of an overall animation's duration, at which the value will hold true for the animation. The value for the animation between keyframes will be calculated as an interpolation between the values at those keyframes.

param
fraction The time, expressed as a value between 0 and 1, representing the fraction of time elapsed of the overall animation duration.

        return new IntKeyframe(fraction);
    
public static android.animation.KeyframeofObject(float fraction, java.lang.Object value)
Constructs a Keyframe object with the given time and value. The time defines the time, as a proportion of an overall animation's duration, at which the value will hold true for the animation. The value for the animation between keyframes will be calculated as an interpolation between the values at those keyframes.

param
fraction The time, expressed as a value between 0 and 1, representing the fraction of time elapsed of the overall animation duration.
param
value The value that the object will animate to as the animation time approaches the time in this keyframe, and the the value animated from as the time passes the time in this keyframe.

        return new ObjectKeyframe(fraction, value);
    
public static android.animation.KeyframeofObject(float fraction)
Constructs a Keyframe object with the given time. The value at this time will be derived from the target object when the animation first starts (note that this implies that keyframes with no initial value must be used as part of an {@link ObjectAnimator}). The time defines the time, as a proportion of an overall animation's duration, at which the value will hold true for the animation. The value for the animation between keyframes will be calculated as an interpolation between the values at those keyframes.

param
fraction The time, expressed as a value between 0 and 1, representing the fraction of time elapsed of the overall animation duration.

        return new ObjectKeyframe(fraction, null);
    
public voidsetFraction(float fraction)
Sets the time for this keyframe, as a fraction of the overall animation duration.

param
fraction time associated with this keyframe, as a fraction of the overall animation duration. This should be a value between 0 and 1.

        mFraction = fraction;
    
public voidsetInterpolator(TimeInterpolator interpolator)
Sets the optional interpolator for this Keyframe. A value of null indicates that there is no interpolation, which is the same as linear interpolation.

return
The optional interpolator for this Keyframe.

        mInterpolator = interpolator;
    
public abstract voidsetValue(java.lang.Object value)
Sets the value for this Keyframe.

param
value value for this Keyframe.

voidsetValueWasSetOnStart(boolean valueWasSetOnStart)

        mValueWasSetOnStart = valueWasSetOnStart;
    
booleanvalueWasSetOnStart()
If the Keyframe's value was acquired from the target object, this flag should be set so that, if target changes, value will be reset.

return
boolean Whether this Keyframe's value was retieved from the target object or not.

        return mValueWasSetOnStart;