Title: How to chain animation in android to the same view?
Tags: android;animation;view;chaining;chained
Question: I got some text views and I want to make the buzz effect of MSN.

My plan is:


take the view, let say 10dip to the left,
take it back to its start position
after that take it 10dip up
then back
down back
left... and so on.


My point is, I have some sequence of movements that I want to set to one view and that needs to execute one after another.

How can I do that?


Here is the accepted answer: Use an AnimationSet:

```AnimationSet set = new AnimationSet(true);

Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(100);
set.addAnimation(animation);

animation = new TranslateAnimation(
    Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
    Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f
);
animation.setDuration(500);
set.addAnimation(animation);

view.startAnimation( set );
```

Comment for this answer: This answer is not correct. Animations will launch simulatneously.
Comment for this answer: Can you at least modify it? It's really confusing.
Comment for this answer: I agree, this answer is just wrong. But I can't delete it as it has been accepted... @Lukap, please un-accept it.
Comment for this answer: I can't delete it neither as it has been accepted... @Lukap, please un-accept it and ping me.
Comment for this answer: This is indeed perfectly usable:
`
        animDown.duration = 100;
        animUp.duration = 300;
        animUp.startOffset = animDown.duration;

        val set = AnimationSet(true);
        set.addAnimation(animDown);
        set.addAnimation(animUp);
        view.startAnimation(set);`
Comment for this answer: Just tried AnimationSet and doesn't chain animation. They are executed at the same time. This answer is wrong.
Comment for this answer: AnimationSet performs animations asynchronously. To achieve the desired effect, you need to use AnimationSet.setStartOffset() in the second animation
Comment for this answer: What??? This is wrong, animationSet animates its child animations together. "AnimationSet: Represents a group of Animations that should be played together."

Here is another answer: I have the beginnings of an sdk 15 compatible class that can be used to build complex animation chains hope it helps someone. You should be able to follow the design pattern to add your own methods. If you do please comment them here and I will update the answer, Cheers!

```package com.stuartclark45.magicmatt.util;

import java.util.LinkedList;
import java.util.List;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.view.View;

    /**
     * Used to build complex animations for a view. Example usage bellow makes view move out to the
     * right whilst rotating 45 degrees, then move out to the left.
     *
     * {@code
     *  int rotateDuration = 200;
     *  int rotation = 45;
     *  new AnimationBuilder(view)
     *    .translationX(100, rotateDuration)
     *    .rotateTo(rotation, rotateDuration)
     *    .then()
     *    .translationX(-200, rotateDuration)
     *    .start();
     * }
     *
     * @author Stuart Clark
     */

    public class AnimationBuilder {

      private View view;
      private List<Animator&gt; setsList;
      private List<Animator&gt; buildingList;

      public AnimationBuilder(View view) {
        this.view = view;
        this.setsList = new LinkedList<&gt;();
        this.buildingList = new LinkedList<&gt;();
      }

      public AnimationBuilder rotateTo(float deg, long duration) {
        buildingList.add(ObjectAnimator.ofFloat(view, "rotation", deg).setDuration(duration));
        return this;
      }

      public AnimationBuilder translationX(int deltaX, long duration) {
        buildingList.add(ObjectAnimator.ofFloat(view, "translationX", deltaX).setDuration(duration));
        return this;
      }

      public AnimationBuilder translationY(int deltaX, long duration) {
        buildingList.add(ObjectAnimator.ofFloat(view, "translationY", deltaX).setDuration(duration));
        return this;
      }

      public AnimationBuilder then() {
        createAniSet();
        // Reset the building list
        buildingList = new LinkedList<&gt;();
        return this;
      }

      public void start() {
        createAniSet();
        AnimatorSet metaSet = new AnimatorSet();
        metaSet.playSequentially(setsList);
        metaSet.start();
      }

      private void createAniSet() {
        AnimatorSet aniSet = new AnimatorSet();
        aniSet.playTogether(buildingList);
        setsList.add(aniSet);
      }


    }
```


Here is another answer: You probably mean AnimatorSet (not AnimationSet). As written in documentation:
```
This class plays a set of ```Animator``` objects in the specified order. Animations can be set up to play together, in sequence, or after a specified delay.
There are two different approaches to adding animations to a AnimatorSet: either the ```playTogether()``` or ```playSequentially()``` methods can be called to add a set of animations all at once, or the ```play(Animator)``` can be used in conjunction with methods in the ```Builder``` class to add animations one by one.
```
Animation which moves ```view``` by ```-100px``` for ```700ms``` and then disappears during ```300ms```:
```final View view = findViewById(R.id.my_view);

final Animator translationAnimator = ObjectAnimator
        .ofFloat(view, View.TRANSLATION_Y, 0f, -100f)
        .setDuration(700);

final Animator alphaAnimator = ObjectAnimator
        .ofFloat(view, View.ALPHA, 1f, 0f)
        .setDuration(300);

final AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playSequentially(
        translationAnimator,
        alphaAnimator
);
animatorSet.start()
```

Comment for this answer: Don't forget `animatorSet.start()`

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2011:00:06/07/11', 'FavoriteCount': 3.0, 'PostTypeId': 1, 'Tags': '<android><animation><view><chaining><chained>', 'Title': 'How to chain animation in android to the same view?', 'ViewCount': 11862, 'id': 6267473, 'user_AboutMe': '<p>Before I was user706780 :-),than Luk ,than ....</p>\n', 'user_AccountId': 363188.0, 'user_DisplayName': 'Lukap', 'user_Reputation': 30916.0, 'user_Views': 1340.0, 'user_id': 706780.0}}