Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run several translate animations sequentially?

Tags:

android

I want to run the three translate animations shown below sequentially. i.e. after one translate animation ends, the second translate animation starts. However, they run concurrently.

Additionally, this animation will be used for overridePendingTransition() as a parameter. So, I have to solve this problem, only by using XML code.

Is there anyone who knows what I should do?

<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">

<translate
    android:fromXDelta="100%p"
    android:toXDelta="-20%p"
    android:duration="1000" />

<translate
    android:fromXDelta="-20%p"
    android:toXDelta="20%p"
    android:duration="1000" />

<translate
    android:fromXDelta="20%p"
    android:toXDelta="0"
    android:duration="1000" />
</set>
like image 992
howisgeek Avatar asked Dec 19 '10 09:12

howisgeek


2 Answers

Use android:startOffset to delay animations.

With your example, this should do what you want:

<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:fillAfter="true">

    <translate
        android:fromXDelta="100%p"
        android:toXDelta="-20%p"
        android:duration="1000" />

    <translate
        android:startOffset="1000"
        android:fromXDelta="-20%p"
        android:toXDelta="20%p"
        android:duration="1000" />

    <translate
        android:startOffset="2000"
        android:fromXDelta="20%p"
        android:toXDelta="0"
        android:duration="1000" />
</set>
like image 172
Kevin Gaudin Avatar answered Nov 17 '22 23:11

Kevin Gaudin


Kevin's solution may work, though I have found the timing to be somewhat inaccurate.

Another option is to use a pair of AnimationListener objects, one attached to each of the first two Animations. The listener for the first animation, in onAnimationEnd(), would start the second animation. The listener for the second animation, in onAnimationEnd(), would start the third animation.

like image 18
CommonsWare Avatar answered Nov 17 '22 23:11

CommonsWare