FileDocCategorySizeDatePackage
TranslateAnimation.javaAPI DocAndroid 1.5 API6619Wed May 06 22:41:56 BST 2009android.view.animation

TranslateAnimation

public class TranslateAnimation extends Animation
An animation that controls the position of an object. See the {@link android.view.animation full package} description for details and sample code.

Fields Summary
private int
mFromXType
private int
mToXType
private int
mFromYType
private int
mToYType
private float
mFromXValue
private float
mToXValue
private float
mFromYValue
private float
mToYValue
private float
mFromXDelta
private float
mToXDelta
private float
mFromYDelta
private float
mToYDelta
Constructors Summary
public TranslateAnimation(android.content.Context context, android.util.AttributeSet attrs)
Constructor used when a TranslateAnimation is loaded from a resource.

param
context Application context to use
param
attrs Attribute set from which to read values


                                   
         
        super(context, attrs);

        TypedArray a = context.obtainStyledAttributes(attrs,
                com.android.internal.R.styleable.TranslateAnimation);

        Description d = Description.parseValue(a.peekValue(
            com.android.internal.R.styleable.TranslateAnimation_fromXDelta));
        mFromXType = d.type;
        mFromXValue = d.value;

        d = Description.parseValue(a.peekValue(
                com.android.internal.R.styleable.TranslateAnimation_toXDelta));
        mToXType = d.type;
        mToXValue = d.value;

        d = Description.parseValue(a.peekValue(
            com.android.internal.R.styleable.TranslateAnimation_fromYDelta));
        mFromYType = d.type;
        mFromYValue = d.value;

        d = Description.parseValue(a.peekValue(
            com.android.internal.R.styleable.TranslateAnimation_toYDelta));
        mToYType = d.type;
        mToYValue = d.value;

        a.recycle();
    
public TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
Constructor to use when building a TranslateAnimation from code

param
fromXDelta Change in X coordinate to apply at the start of the animation
param
toXDelta Change in X coordinate to apply at the end of the animation
param
fromYDelta Change in Y coordinate to apply at the start of the animation
param
toYDelta Change in Y coordinate to apply at the end of the animation

        mFromXValue = fromXDelta;
        mToXValue = toXDelta;
        mFromYValue = fromYDelta;
        mToYValue = toYDelta;

        mFromXType = ABSOLUTE;
        mToXType = ABSOLUTE;
        mFromYType = ABSOLUTE;
        mToYType = ABSOLUTE;
    
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

param
fromXType Specifies how fromXValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
param
fromXValue 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.
param
toXType Specifies how toXValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
param
toXValue 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.
param
fromYType Specifies how fromYValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
param
fromYValue 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.
param
toYType Specifies how toYValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
param
toYValue 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.


        mFromXValue = fromXValue;
        mToXValue = toXValue;
        mFromYValue = fromYValue;
        mToYValue = toYValue;

        mFromXType = fromXType;
        mToXType = toXType;
        mFromYType = fromYType;
        mToYType = toYType;
    
Methods Summary
protected voidapplyTransformation(float interpolatedTime, Transformation t)

        float dx = mFromXDelta;
        float dy = mFromYDelta;
        if (mFromXDelta != mToXDelta) {
            dx = mFromXDelta + ((mToXDelta - mFromXDelta) * interpolatedTime);
        }
        if (mFromYDelta != mToYDelta) {
            dy = mFromYDelta + ((mToYDelta - mFromYDelta) * interpolatedTime);
        }
        t.getMatrix().setTranslate(dx, dy);
    
public voidinitialize(int width, int height, int parentWidth, int parentHeight)

        super.initialize(width, height, parentWidth, parentHeight);
        mFromXDelta = resolveSize(mFromXType, mFromXValue, width, parentWidth);
        mToXDelta = resolveSize(mToXType, mToXValue, width, parentWidth);
        mFromYDelta = resolveSize(mFromYType, mFromYValue, height, parentHeight);
        mToYDelta = resolveSize(mToYType, mToYValue, height, parentHeight);