Skip to content

Most visited

Recently visited

navigation
added in version 25.4.0
belongs to Maven artifact com.android.support:support-dynamic-animation:27.0.0

DynamicAnimation

public abstract class DynamicAnimation
extends Object

java.lang.Object
   ↳ android.support.animation.DynamicAnimation<T extends android.support.animation.DynamicAnimation<T>>
Known Direct Subclasses


This class is the base class of physics-based animations. It manages the animation's lifecycle such as start() and cancel(). This base class also handles the common setup for all the subclass animations. For example, DynamicAnimation supports adding DynamicAnimation.OnAnimationEndListener and DynamicAnimation.OnAnimationUpdateListener so that the important animation events can be observed through the callbacks. The start conditions for any subclass of DynamicAnimation can be set using setStartValue(float) and setStartVelocity(float).

Summary

Nested classes

interface DynamicAnimation.OnAnimationEndListener

An animation listener that receives end notifications from an animation. 

interface DynamicAnimation.OnAnimationUpdateListener

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

class DynamicAnimation.ViewProperty

ViewProperty holds the access of a property of a View

Constants

float MIN_VISIBLE_CHANGE_ALPHA

The minimum visible change in alpha that can be visible to users.

float MIN_VISIBLE_CHANGE_PIXELS

The minimum visible change in pixels that can be visible to users.

float MIN_VISIBLE_CHANGE_ROTATION_DEGREES

The minimum visible change in degrees that can be visible to users.

float MIN_VISIBLE_CHANGE_SCALE

The minimum visible change in scale that can be visible to users.

Fields

public static final DynamicAnimation.ViewProperty ALPHA

View's alpha property.

public static final DynamicAnimation.ViewProperty ROTATION

View's rotation property.

public static final DynamicAnimation.ViewProperty ROTATION_X

View's rotationX property.

public static final DynamicAnimation.ViewProperty ROTATION_Y

View's rotationY property.

public static final DynamicAnimation.ViewProperty SCALE_X

View's scaleX property.

public static final DynamicAnimation.ViewProperty SCALE_Y

View's scaleY property.

public static final DynamicAnimation.ViewProperty SCROLL_X

View's scrollX property.

public static final DynamicAnimation.ViewProperty SCROLL_Y

View's scrollY property.

public static final DynamicAnimation.ViewProperty TRANSLATION_X

View's translationX property.

public static final DynamicAnimation.ViewProperty TRANSLATION_Y

View's translationY property.

public static final DynamicAnimation.ViewProperty TRANSLATION_Z

View's translationZ property.

public static final DynamicAnimation.ViewProperty X

View's x property.

public static final DynamicAnimation.ViewProperty Y

View's y property.

public static final DynamicAnimation.ViewProperty Z

View's z property.

Public methods

T addEndListener(DynamicAnimation.OnAnimationEndListener listener)

Adds an end listener to the animation for receiving onAnimationEnd callbacks.

T addUpdateListener(DynamicAnimation.OnAnimationUpdateListener listener)

Adds an update listener to the animation for receiving per-frame animation update callbacks.

void cancel()

Cancels the on-going animation.

float getMinimumVisibleChange()

Returns the minimum change in the animation property that could be visibly different to users.

boolean isRunning()

Returns whether the animation is currently running.

void removeEndListener(DynamicAnimation.OnAnimationEndListener listener)

Removes the end listener from the animation, so as to stop receiving animation end callbacks.

void removeUpdateListener(DynamicAnimation.OnAnimationUpdateListener listener)

Removes the update listener from the animation, so as to stop receiving animation update callbacks.

T setMaxValue(float max)

Sets the max value of the animation.

T setMinValue(float min)

Sets the min value of the animation.

T setMinimumVisibleChange(float minimumVisibleChange)

This method sets the minimal change of animation value that is visible to users, which helps determine a reasonable threshold for the animation's termination condition.

T setStartValue(float startValue)

Sets the start value of the animation.

T setStartVelocity(float startVelocity)

Start velocity of the animation.

void start()

Starts an animation.

Inherited methods

From class java.lang.Object

Constants

MIN_VISIBLE_CHANGE_ALPHA

added in version 25.4.0
float MIN_VISIBLE_CHANGE_ALPHA

The minimum visible change in alpha that can be visible to users.

Constant Value: 0.00390625

MIN_VISIBLE_CHANGE_PIXELS

added in version 25.4.0
float MIN_VISIBLE_CHANGE_PIXELS

The minimum visible change in pixels that can be visible to users.

Constant Value: 1.0

MIN_VISIBLE_CHANGE_ROTATION_DEGREES

added in version 25.4.0
float MIN_VISIBLE_CHANGE_ROTATION_DEGREES

The minimum visible change in degrees that can be visible to users.

Constant Value: 0.1

MIN_VISIBLE_CHANGE_SCALE

added in version 25.4.0
float MIN_VISIBLE_CHANGE_SCALE

The minimum visible change in scale that can be visible to users.

Constant Value: 0.002

Fields

ALPHA

added in version 25.4.0
DynamicAnimation.ViewProperty ALPHA

View's alpha property.

ROTATION

added in version 25.4.0
DynamicAnimation.ViewProperty ROTATION

View's rotation property.

ROTATION_X

added in version 25.4.0
DynamicAnimation.ViewProperty ROTATION_X

View's rotationX property.

ROTATION_Y

added in version 25.4.0
DynamicAnimation.ViewProperty ROTATION_Y

View's rotationY property.

SCALE_X

added in version 25.4.0
DynamicAnimation.ViewProperty SCALE_X

View's scaleX property.

SCALE_Y

added in version 25.4.0
DynamicAnimation.ViewProperty SCALE_Y

View's scaleY property.

SCROLL_X

added in version 25.4.0
DynamicAnimation.ViewProperty SCROLL_X

View's scrollX property.

SCROLL_Y

added in version 25.4.0
DynamicAnimation.ViewProperty SCROLL_Y

View's scrollY property.

TRANSLATION_X

added in version 25.4.0
DynamicAnimation.ViewProperty TRANSLATION_X

View's translationX property.

TRANSLATION_Y

added in version 25.4.0
DynamicAnimation.ViewProperty TRANSLATION_Y

View's translationY property.

TRANSLATION_Z

added in version 25.4.0
DynamicAnimation.ViewProperty TRANSLATION_Z

View's translationZ property.

X

added in version 25.4.0
DynamicAnimation.ViewProperty X

View's x property.

Y

added in version 25.4.0
DynamicAnimation.ViewProperty Y

View's y property.

Z

added in version 25.4.0
DynamicAnimation.ViewProperty Z

View's z property.

Public methods

addEndListener

added in version 25.4.0
T addEndListener (DynamicAnimation.OnAnimationEndListener listener)

Adds an end listener to the animation for receiving onAnimationEnd callbacks. If the listener is null or has already been added to the list of listeners for the animation, no op.

Parameters
listener DynamicAnimation.OnAnimationEndListener: the listener to be added

Returns
T the animation to which the listener is added

addUpdateListener

added in version 25.4.0
T addUpdateListener (DynamicAnimation.OnAnimationUpdateListener listener)

Adds an update listener to the animation for receiving per-frame animation update callbacks. If the listener is null or has already been added to the list of listeners for the animation, no op.

Note that update listener should only be added before the start of the animation.

Parameters
listener DynamicAnimation.OnAnimationUpdateListener: the listener to be added

Returns
T the animation to which the listener is added

Throws
UnsupportedOperationException if the update listener is added after the animation has started

cancel

added in version 25.4.0
void cancel ()

Cancels the on-going animation. If the animation hasn't started, no op. Note that this method should only be called on main thread.

Throws
AndroidRuntimeException if this method is not called on the main thread

getMinimumVisibleChange

added in version 25.4.0
float getMinimumVisibleChange ()

Returns the minimum change in the animation property that could be visibly different to users.

Returns
float minimum change in property value that is visible to users

isRunning

added in version 25.4.0
boolean isRunning ()

Returns whether the animation is currently running.

Returns
boolean true if the animation is currently running, false otherwise

removeEndListener

added in version 25.4.0
void removeEndListener (DynamicAnimation.OnAnimationEndListener listener)

Removes the end listener from the animation, so as to stop receiving animation end callbacks.

Parameters
listener DynamicAnimation.OnAnimationEndListener: the listener to be removed

removeUpdateListener

added in version 25.4.0
void removeUpdateListener (DynamicAnimation.OnAnimationUpdateListener listener)

Removes the update listener from the animation, so as to stop receiving animation update callbacks.

Parameters
listener DynamicAnimation.OnAnimationUpdateListener: the listener to be removed

setMaxValue

added in version 25.4.0
T setMaxValue (float max)

Sets the max value of the animation. Animations will not animate beyond their max value. Whether or not animation will come to an end when max value is reached is dependent on the child animation's implementation.

Parameters
max float: maximum value of the property to be animated

Returns
T the Animation whose max value is being set

setMinValue

added in version 25.4.0
T setMinValue (float min)

Sets the min value of the animation. Animations will not animate beyond their min value. Whether or not animation will come to an end when min value is reached is dependent on the child animation's implementation.

Parameters
min float: minimum value of the property to be animated

Returns
T the Animation whose min value is being set

setMinimumVisibleChange

added in version 25.4.0
T setMinimumVisibleChange (float minimumVisibleChange)

This method sets the minimal change of animation value that is visible to users, which helps determine a reasonable threshold for the animation's termination condition. It is critical to set the minimal visible change for custom properties (i.e. non-ViewPropertys) unless the custom property is in pixels.

For custom properties, this minimum visible change defaults to change in pixel (i.e. MIN_VISIBLE_CHANGE_PIXELS. It is recommended to adjust this value that is reasonable for the property to be animated. A general rule of thumb to calculate such a value is: minimum visible change = range of custom property value / corresponding pixel range. For example, if the property to be animated is a progress (from 0 to 100) that corresponds to a 200-pixel change. Then the min visible change should be 100 / 200. (i.e. 0.5).

It's not necessary to call this method when animating DynamicAnimation.ViewPropertys, as the minimum visible change will be derived from the property. For example, if the property to be animated is in pixels (i.e. TRANSLATION_X, TRANSLATION_Y, TRANSLATION_Z, @SCROLL_X or SCROLL_Y), the default minimum visible change is 1 (pixel). For ROTATION, ROTATION_X or ROTATION_Y, the animation will use MIN_VISIBLE_CHANGE_ROTATION_DEGREES as the min visible change, which is 1/10. Similarly, the minimum visible change for alpha ( i.e. MIN_VISIBLE_CHANGE_ALPHA is defined as 1 / 256.

Parameters
minimumVisibleChange float: minimum change in property value that is visible to users

Value is 0.0 or greater.

Returns
T the animation whose min visible change is being set

Throws
IllegalArgumentException if the given threshold is not positive

setStartValue

added in version 25.4.0
T setStartValue (float startValue)

Sets the start value of the animation. If start value is not set, the animation will get the current value for the view's property, and use that as the start value.

Parameters
startValue float: start value for the animation

Returns
T the Animation whose start value is being set

setStartVelocity

added in version 25.4.0
T setStartVelocity (float startVelocity)

Start velocity of the animation. Default velocity is 0. Unit: change in property per second (e.g. pixels per second, scale/alpha value change per second).

Note when using a fixed value as the start velocity (as opposed to getting the velocity through touch events), it is recommended to define such a value in dp/second and convert it to pixel/second based on the density of the screen to achieve a consistent look across different screens.

To convert from dp/second to pixel/second:

 float pixelPerSecond = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpPerSecond,
         getResources().getDisplayMetrics());
 

Parameters
startVelocity float: start velocity of the animation

Returns
T the Animation whose start velocity is being set

start

added in version 25.4.0
void start ()

Starts an animation. If the animation has already been started, no op. Note that calling start() will not immediately set the property value to start value of the animation. The property values will be changed at each animation pulse, which happens before the draw pass. As a result, the changes will be reflected in the next frame, the same as if the values were set immediately. This method should only be called on main thread.

Throws
AndroidRuntimeException if this method is not called on the main thread
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)