# Keyframe

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/android/animation/Keyframe#pubctors)\|[Methods](https://developer.android.com/reference/android/animation/Keyframe#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/animation/Keyframe#inhmethods)  

# Keyframe

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/animation/Keyframe "View this page in Kotlin")\|Java

`
public


abstract
class
Keyframe
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


implements

`[Cloneable](https://developer.android.com/reference/java/lang/Cloneable)`


`

|---|----------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.animation.Keyframe |

<br />

*** ** * ** ***

This class holds a time/value pair for an animation. The Keyframe class is used by[ValueAnimator](https://developer.android.com/reference/android/animation/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[TimeInterpolator](https://developer.android.com/reference/android/animation/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[TypeEvaluator](https://developer.android.com/reference/android/animation/TypeEvaluator)), you should stick to using float and int as animations using those types have lower runtime overhead than other types.

<br />

## Summary

|                                       ### Public constructors                                        ||
|---------------------------------------------------------------------------------------------------|---|
| ` `[Keyframe](https://developer.android.com/reference/android/animation/Keyframe#Keyframe())`() ` |

|                                                                                                                                                                                                 ### Public methods                                                                                                                                                                                                  ||
|---------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract `[Keyframe](https://developer.android.com/reference/android/animation/Keyframe)        | ` `[clone](https://developer.android.com/reference/android/animation/Keyframe#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                                           |
| ` float`                                                                                          | ` `[getFraction](https://developer.android.com/reference/android/animation/Keyframe#getFraction())`() ` Gets the time for this keyframe, as a fraction of the overall animation duration.                                                                                                                        |
| ` `[TimeInterpolator](https://developer.android.com/reference/android/animation/TimeInterpolator) | ` `[getInterpolator](https://developer.android.com/reference/android/animation/Keyframe#getInterpolator())`() ` Gets the optional interpolator for this Keyframe.                                                                                                                                                |
| ` `[Class](https://developer.android.com/reference/java/lang/Class)`<T>`                          | ` `[getType](https://developer.android.com/reference/android/animation/Keyframe#getType())`() ` Gets the type of keyframe.                                                                                                                                                                                       |
| ` abstract `[Object](https://developer.android.com/reference/java/lang/Object)                    | ` `[getValue](https://developer.android.com/reference/android/animation/Keyframe#getValue())`() ` Gets the value for this Keyframe.                                                                                                                                                                              |
| ` boolean`                                                                                        | ` `[hasValue](https://developer.android.com/reference/android/animation/Keyframe#hasValue())`() ` Indicates whether this keyframe has a valid value.                                                                                                                                                             |
| ` static `[Keyframe](https://developer.android.com/reference/android/animation/Keyframe)          | ` `[ofFloat](https://developer.android.com/reference/android/animation/Keyframe#ofFloat(float))`(float fraction) ` Constructs a Keyframe object with the given time.                                                                                                                                             |
| ` static `[Keyframe](https://developer.android.com/reference/android/animation/Keyframe)          | ` `[ofFloat](https://developer.android.com/reference/android/animation/Keyframe#ofFloat(float,%20float))`(float fraction, float value) ` Constructs a Keyframe object with the given time and value.                                                                                                             |
| ` static `[Keyframe](https://developer.android.com/reference/android/animation/Keyframe)          | ` `[ofInt](https://developer.android.com/reference/android/animation/Keyframe#ofInt(float,%20int))`(float fraction, int value) ` Constructs a Keyframe object with the given time and value.                                                                                                                     |
| ` static `[Keyframe](https://developer.android.com/reference/android/animation/Keyframe)          | ` `[ofInt](https://developer.android.com/reference/android/animation/Keyframe#ofInt(float))`(float fraction) ` Constructs a Keyframe object with the given time.                                                                                                                                                 |
| ` static `[Keyframe](https://developer.android.com/reference/android/animation/Keyframe)          | ` `[ofObject](https://developer.android.com/reference/android/animation/Keyframe#ofObject(float,%20java.lang.Object))`(float fraction, `[Object](https://developer.android.com/reference/java/lang/Object)` value) ` Constructs a Keyframe object with the given time and value.                                 |
| ` static `[Keyframe](https://developer.android.com/reference/android/animation/Keyframe)          | ` `[ofObject](https://developer.android.com/reference/android/animation/Keyframe#ofObject(float))`(float fraction) ` Constructs a Keyframe object with the given time.                                                                                                                                           |
| ` void`                                                                                           | ` `[setFraction](https://developer.android.com/reference/android/animation/Keyframe#setFraction(float))`(float fraction) ` Sets the time for this keyframe, as a fraction of the overall animation duration.                                                                                                     |
| ` void`                                                                                           | ` `[setInterpolator](https://developer.android.com/reference/android/animation/Keyframe#setInterpolator(android.animation.TimeInterpolator))`(`[TimeInterpolator](https://developer.android.com/reference/android/animation/TimeInterpolator)` interpolator) ` Sets the optional interpolator for this Keyframe. |
| ` abstract void`                                                                                  | ` `[setValue](https://developer.android.com/reference/android/animation/Keyframe#setValue(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` value) ` Sets the value for this Keyframe.                                                                                    |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public constructors

### Keyframe

```
public Keyframe ()
```

<br />

<br />

## Public methods

### clone

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract Keyframe clone ()
```

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object`x`, the expression:
>
> ```
>  x.clone() != x
> ```
will be true, and that the expression:
>
> ```
>  x.clone().getClass() == x.getClass()
> ```
will be`true`, but these are not absolute requirements. While it is typically the case that:
>
> ```
>  x.clone().equals(x)
> ```
will be`true`, this is not an absolute requirement.

By convention, the returned object should be obtained by calling`super.clone`. If a class and all of its superclasses (except`Object`) obey this convention, it will be the case that`x.clone().getClass() == x.getClass()`.

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by`super.clone`before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by`super.clone`need to be modified.

<br />

|                                                     Returns                                                      ||
|--------------------------------------------------------------------------------|----------------------------------|
| [Keyframe](https://developer.android.com/reference/android/animation/Keyframe) | a clone of this instance. <br /> |

### getFraction

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public float getFraction ()
```

Gets the time for this keyframe, as a fraction of the overall animation duration.

<br />

|                                                                     Returns                                                                      ||
|---------|-----------------------------------------------------------------------------------------------------------------------------------------|
| `float` | The time associated with this keyframe, as a fraction of the overall animation duration. This should be a value between 0 and 1. <br /> |

### getInterpolator

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public TimeInterpolator getInterpolator ()
```

Gets the optional interpolator for this Keyframe. A value of`null`indicates that there is no interpolation, which is the same as linear interpolation.

<br />

|                                                                       Returns                                                                       ||
|------------------------------------------------------------------------------------------------|-----------------------------------------------------|
| [TimeInterpolator](https://developer.android.com/reference/android/animation/TimeInterpolator) | The optional interpolator for this Keyframe. <br /> |

### getType

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Class<T> getType ()
```

Gets the type of keyframe. This information is used by ValueAnimator to determine the type of[TypeEvaluator](https://developer.android.com/reference/android/animation/TypeEvaluator)to use when calculating values between keyframes. The type is based on the type of Keyframe created.

<br />

|                                                           Returns                                                           ||
|-----------------------------------------------------------------------|------------------------------------------------------|
| [Class](https://developer.android.com/reference/java/lang/Class)`<T>` | The type of the value stored in the Keyframe. <br /> |

### getValue

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract Object getValue ()
```

Gets the value for this Keyframe.

<br />

|                                                 Returns                                                 ||
|--------------------------------------------------------------------|-------------------------------------|
| [Object](https://developer.android.com/reference/java/lang/Object) | The value for this Keyframe. <br /> |

### hasValue

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean hasValue ()
```

Indicates whether this keyframe has a valid value. This method is called internally when an[ObjectAnimator](https://developer.android.com/reference/android/animation/ObjectAnimator)first starts; keyframes without values are assigned values at that time by deriving the value for the property from the target object.

<br />

|                               Returns                               ||
|-----------|----------------------------------------------------------|
| `boolean` | boolean Whether this object has a value assigned. <br /> |

### ofFloat

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Keyframe ofFloat (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[ObjectAnimator](https://developer.android.com/reference/android/animation/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.

<br />

|                                                                        Parameters                                                                        ||
|------------|----------------------------------------------------------------------------------------------------------------------------------------------|
| `fraction` | `float`: The time, expressed as a value between 0 and 1, representing the fraction of time elapsed of the overall animation duration. <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Keyframe](https://developer.android.com/reference/android/animation/Keyframe) | <br /> |

### ofFloat

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Keyframe ofFloat (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.

<br />

|                                                                                                 Parameters                                                                                                  ||
|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `fraction` | `float`: The time, expressed as a value between 0 and 1, representing the fraction of time elapsed of the overall animation duration. <br />                                                    |
| `value`    | `float`: The value that the object will animate to as the animation time approaches the time in this keyframe, and the value animated from as the time passes the time in this keyframe. <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Keyframe](https://developer.android.com/reference/android/animation/Keyframe) | <br /> |

### ofInt

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Keyframe ofInt (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.

<br />

|                                                                                                Parameters                                                                                                 ||
|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `fraction` | `float`: The time, expressed as a value between 0 and 1, representing the fraction of time elapsed of the overall animation duration. <br />                                                  |
| `value`    | `int`: The value that the object will animate to as the animation time approaches the time in this keyframe, and the value animated from as the time passes the time in this keyframe. <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Keyframe](https://developer.android.com/reference/android/animation/Keyframe) | <br /> |

### ofInt

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Keyframe ofInt (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[ObjectAnimator](https://developer.android.com/reference/android/animation/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.

<br />

|                                                                        Parameters                                                                        ||
|------------|----------------------------------------------------------------------------------------------------------------------------------------------|
| `fraction` | `float`: The time, expressed as a value between 0 and 1, representing the fraction of time elapsed of the overall animation duration. <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Keyframe](https://developer.android.com/reference/android/animation/Keyframe) | <br /> |

### ofObject

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Keyframe ofObject (float fraction, 
                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.

<br />

|                                                                                                  Parameters                                                                                                  ||
|------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `fraction` | `float`: The time, expressed as a value between 0 and 1, representing the fraction of time elapsed of the overall animation duration. <br />                                                     |
| `value`    | `Object`: The value that the object will animate to as the animation time approaches the time in this keyframe, and the value animated from as the time passes the time in this keyframe. <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Keyframe](https://developer.android.com/reference/android/animation/Keyframe) | <br /> |

### ofObject

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Keyframe ofObject (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[ObjectAnimator](https://developer.android.com/reference/android/animation/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.

<br />

|                                                                        Parameters                                                                        ||
|------------|----------------------------------------------------------------------------------------------------------------------------------------------|
| `fraction` | `float`: The time, expressed as a value between 0 and 1, representing the fraction of time elapsed of the overall animation duration. <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [Keyframe](https://developer.android.com/reference/android/animation/Keyframe) | <br /> |

### setFraction

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setFraction (float fraction)
```

Sets the time for this keyframe, as a fraction of the overall animation duration.

<br />

|                                                                        Parameters                                                                        ||
|------------|----------------------------------------------------------------------------------------------------------------------------------------------|
| `fraction` | `float`: time associated with this keyframe, as a fraction of the overall animation duration. This should be a value between 0 and 1. <br /> |

### setInterpolator

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setInterpolator (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.

<br />

|                Parameters                 ||
|----------------|---------------------------|
| `interpolator` | `TimeInterpolator` <br /> |

|                           Returns                           ||
|--------|-----------------------------------------------------|
| `void` | The optional interpolator for this Keyframe. <br /> |

### setValue

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void setValue (Object value)
```

Sets the value for this Keyframe.

<br />

|                     Parameters                     ||
|---------|-------------------------------------------|
| `value` | `Object`: value for this Keyframe. <br /> |