user2853108
user2853108

Reputation: 1311

Android animation with sets

I have an animation like this:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false"
    android:fillAfter="true" >
<translate
    android:interpolator="@android:anim/decelerate_interpolator"
    android:duration="600"
    android:fillAfter="true"
    android:fromXDelta="10"
    android:fromYDelta="0"
    android:toXDelta="0%"
    android:toYDelta="-500" />

    </set>

And it works fantastic, however this is not all I want to do, I want the view to go up and then to go back down. To accomplish this I then change the animation to the following:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false"
    android:fillAfter="true" >
<translate
    android:interpolator="@android:anim/decelerate_interpolator"
    android:duration="600"
    android:fillAfter="true"
    android:fromXDelta="10"
    android:fromYDelta="0"
    android:toXDelta="0%"
    android:toYDelta="-500" />
    <translate
        android:interpolator="@android:anim/decelerate_interpolator"
        android:duration="600"
        android:fillAfter="true"
        android:fromXDelta="10"
        android:fromYDelta="0"
        android:toXDelta="0%"
        android:toYDelta="500" />

    </set>

However then it doesn't work. I would like one animation to exevute after the other, however I am guessing that they are both executing at the same time. In this case I simply need to be able to do the opposite of the first animation, however I would like to know how to do a scale after a translate and so on. Do I need two separate animations? What is the correct way to run animations after each other instead of all at once?

Upvotes: 1

Views: 1438

Answers (1)

Ben Pearson
Ben Pearson

Reputation: 7752

For the second animation in the set, you want to offset the animation so that it starts after the first one. You can do this by using the offset attribute: http://developer.android.com/reference/android/view/animation/Animation.html#attr_android:startOffset

<translate
    android:interpolator="@android:anim/decelerate_interpolator"
    android:duration="600"

    android:startOffset="600"

    android:fillAfter="true"
    android:fromXDelta="10"
    android:fromYDelta="0"
    android:toXDelta="0%"
    android:toYDelta="500" />

Upvotes: 1

Related Questions