1

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?

BLOB
  • 364
  • 2
  • 7
  • 21

2 Answers2

2

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?

Community
  • 1
  • 1
secretlm
  • 2,361
  • 2
  • 27
  • 38
1

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.

Tigger
  • 8,980
  • 5
  • 36
  • 40
  • No thats not really a solution to the question posed. It requires programme intervention. I mention this because I'm too having a nightmare trying to get sequential animations from a single xml to work. The point of sets and things like startOffset suggest it should be pretty easy. Alas not and poorly documented. – RichieHH Jul 20 '14 at 16:40