Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

TranslateAnimation

public class TranslateAnimation
extends Animation

java.lang.Object
   ↳ android.view.animation.Animation
     ↳ android.view.animation.TranslateAnimation


An animation that controls the position of an object. See the full package description for details and sample code.

Summary

Inherited XML attributes

Inherited constants

Public constructors

TranslateAnimation(Context context, AttributeSet attrs)

Constructor used when a TranslateAnimation is loaded from a resource.

TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)

Constructor to use when building a TranslateAnimation from code

TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)

Constructor to use when building a TranslateAnimation from code

Public methods

void initialize(int width, int height, int parentWidth, int parentHeight)

Initialize this animation with the dimensions of the object being animated as well as the objects parents.

Protected methods

void applyTransformation(float interpolatedTime, Transformation t)

Helper for getTransformation.

Inherited methods

Public constructors

TranslateAnimation

added in API level 1
public TranslateAnimation (Context context, 
                AttributeSet attrs)

Constructor used when a TranslateAnimation is loaded from a resource.

Parameters
context Context: Application context to use

attrs AttributeSet: Attribute set from which to read values

TranslateAnimation

added in API level 1
public TranslateAnimation (float fromXDelta, 
                float toXDelta, 
                float fromYDelta, 
                float toYDelta)

Constructor to use when building a TranslateAnimation from code

Parameters
fromXDelta float: Change in X coordinate to apply at the start of the animation

toXDelta float: Change in X coordinate to apply at the end of the animation

fromYDelta float: Change in Y coordinate to apply at the start of the animation

toYDelta float: Change in Y coordinate to apply at the end of the animation

TranslateAnimation

added in API level 1
public TranslateAnimation (int fromXType, 
                float fromXValue, 
                int toXType, 
                float toXValue, 
                int fromYType, 
                float fromYValue, 
                int toYType, 
                float toYValue)

Constructor to use when building a TranslateAnimation from code

Parameters
fromXType int: Specifies how fromXValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.

fromXValue float: Change in X coordinate to apply at the start of the animation. This value can either be an absolute number if fromXType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.

toXType int: Specifies how toXValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.

toXValue float: Change in X coordinate to apply at the end of the animation. This value can either be an absolute number if toXType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.

fromYType int: Specifies how fromYValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.

fromYValue float: Change in Y coordinate to apply at the start of the animation. This value can either be an absolute number if fromYType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.

toYType int: Specifies how toYValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.

toYValue float: Change in Y coordinate to apply at the end of the animation. This value can either be an absolute number if toYType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.

Public methods

initialize

added in API level 1
public void initialize (int width, 
                int height, 
                int parentWidth, 
                int parentHeight)

Initialize this animation with the dimensions of the object being animated as well as the objects parents. (This is to support animation sizes being specified relative to these dimensions.)

Objects that interpret Animations should call this method when the sizes of the object being animated and its parent are known, and before calling getTransformation(long, Transformation).

Parameters
width int: Width of the object being animated

height int: Height of the object being animated

parentWidth int: Width of the animated object's parent

parentHeight int: Height of the animated object's parent

Protected methods

applyTransformation

added in API level 1
protected void applyTransformation (float interpolatedTime, 
                Transformation t)

Helper for getTransformation. Subclasses should implement this to apply their transforms given an interpolation value. Implementations of this method should always replace the specified Transformation or document they are doing otherwise.

Parameters
interpolatedTime float: The value of the normalized time (0.0 to 1.0) after it has been run through the interpolation function.

t Transformation: The Transformation object to fill in with the current transforms.