BLOB
BLOB

Reputation: 374

android sequential tween animation

Ok.. I got this animation set up for a small imageview for translating from "0%" to "50%" in XML...

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <translate
        android:duration="400"
        android:fromXDelta="0%"        
        android:toXDelta="+50%" />    
</set>

After this, I need to add another sequential animation which would change the Y co-ordinate from "0%" to "50%".. I tried adding another <set> but it did not work... What should I do to get sequential animation?

Upvotes: 1

Views: 1745

Answers (2)

Tigger
Tigger

Reputation: 9130

I'm not completly sure what you really want to do, but if you want to "translate" both the "x" and "y" at the same time simply add android:fromYDelta="0%" and android:toYDelta="+50%" to your existing <translate>.

If you want to "translate" the Y values after the X ones, you will need a new XML file, which you will need to call when the X ones finish.

A quick, untested example:

mAnimatedView = findViewById(R.id.viewToAnimate);

mAnimX = (TranslateAnimation) AnimationUtils.loadAnimation(mContext, R.anim.aX);
mAnimY = (TranslateAnimation) AnimationUtils.loadAnimation(mContext, R.anim.aY);

mAnimX.setAnimationListener(new AnimationListener(){
    @Override
    public void onAnimationEnd(Animation animation) {
        if (mAnimatedView) {
            mAnimatedView.startAnimation(mAnimY);
        }
    }
    @Override
    public void onAnimationRepeat(Animation animation) {
    }
    @Override
    public void onAnimationStart(Animation animation) {
    }
}); 
mAnimY.setAnimationListener(new AnimationListener(){
    @Override
    public void onAnimationEnd(Animation animation) {
        if (mAnimatedView) {
            mAnimatedView.startAnimation(mAnimX);
        }
    }
    @Override
    public void onAnimationRepeat(Animation animation) {
    }
    @Override
    public void onAnimationStart(Animation animation) {
    }
});

mAnimatedView.startAnimation(mAnimX);

Hope that helps and is clear enough.

Upvotes: 1

secretlm
secretlm

Reputation: 2361

You can use android:startOffset to delay animations. Delay in milliseconds before the animation runs, once start time is reached. Must be an integer value, such as "100". -- "developer.android.com"

Another way is you can use AnimationListener to "listen" animations and do whatever you want.

This link is useful for you: How to run several translate animations sequentially?

Upvotes: 2

Related Questions