# AnimatorSet.Builder

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/animation/AnimatorSet.Builder "View this page in Java")  

```
class Builder
```

|---|--------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                 ||
| ↳ | [android.animation.AnimatorSet.Builder](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet.Builder#) |

The`Builder`object is a utility class to facilitate adding animations to a`AnimatorSet`along with the relationships between the various animations. The intention of the`Builder`methods, along with the[play()](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet#play(android.animation.Animator))method of`AnimatorSet`is to make it possible to express the dependency relationships of animations in a natural way. Developers can also use the[playTogether()](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet#playTogether(android.animation.Animator))and[playSequentially()](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet#playSequentially(android.animation.Animator))methods if these suit the need, but it might be easier in some situations to express the AnimatorSet of animations in pairs.

<br />

The`Builder`object cannot be constructed directly, but is rather constructed internally via a call to[AnimatorSet.play(Animator)](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet#play(android.animation.Animator)).

<br />

For example, this sets up a AnimatorSet to play anim1 and anim2 at the same time, anim3 to play when anim2 finishes, and anim4 to play when anim3 finishes:  

```kotlin
AnimatorSet s = new AnimatorSet();
      s.play(anim1).with(anim2);
      s.play(anim2).before(anim3);
      s.play(anim4).after(anim3);
  
```

<br />

Note in the example that both[Builder.before(Animator)](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet.Builder#before(android.animation.Animator))and[android.animation.AnimatorSet.Builder#after(android.animation.Animator)](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet.Builder#after(android.animation.Animator))are used. These are just different ways of expressing the same relationship and are provided to make it easier to say things in a way that is more natural, depending on the situation.

<br />

It is possible to make several calls into the same`Builder`object to express multiple relationships. However, note that it is only the animation passed into the initial[AnimatorSet.play(Animator)](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet#play(android.animation.Animator))method that is the dependency in any of the successive calls to the`Builder`object. For example, the following code starts both anim2 and anim3 when anim1 ends; there is no direct dependency relationship between anim2 and anim3:  

```kotlin
AnimatorSet s = new AnimatorSet();
    s.play(anim1).before(anim2).before(anim3);
  
```
If the desired result is to play anim1 then anim2 then anim3, this code expresses the relationship correctly:

<br />

```kotlin
AnimatorSet s = new AnimatorSet();
    s.play(anim1).before(anim2);
    s.play(anim2).before(anim3);
  
```

<br />

Note that it is possible to express relationships that cannot be resolved and will not result in sensible results. For example,`play(anim1).after(anim1)`makes no sense. In general, circular dependencies like this one (or more indirect ones where a depends on b, which depends on c, which depends on a) should be avoided. Only create AnimatorSets that can boil down to a simple, one-way relationship of animations starting with, before, and after other, different, animations.

## Summary

|                                                                                                                                                                                                                                                                                                                                Public methods                                                                                                                                                                                                                                                                                                                                ||
|-------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| open[AnimatorSet.Builder](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet.Builder#)! | [after](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet.Builder#after(android.animation.Animator))`(`anim:` `[Animator](https://developer.android.com/reference/kotlin/android/animation/Animator)!`)` Sets up the given animation to play when the animation supplied in the[AnimatorSet.play(Animator)](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet#play(android.animation.Animator))call that created this`Builder`object to start when the animation supplied in this method call ends. |
| open[AnimatorSet.Builder](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet.Builder#)! | [after](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet.Builder#after(kotlin.Long))`(`delay:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` Sets up the animation supplied in the[AnimatorSet.play(Animator)](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet#play(android.animation.Animator))call that created this`Builder`object to play when the given amount of time elapses.                                                                          |
| open[AnimatorSet.Builder](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet.Builder#)! | [before](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet.Builder#before(android.animation.Animator))`(`anim:` `[Animator](https://developer.android.com/reference/kotlin/android/animation/Animator)!`)` Sets up the given animation to play when the animation supplied in the[AnimatorSet.play(Animator)](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet#play(android.animation.Animator))call that created this`Builder`object ends.                                                        |
| open[AnimatorSet.Builder](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet.Builder#)! | [with](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet.Builder#with(android.animation.Animator))`(`anim:` `[Animator](https://developer.android.com/reference/kotlin/android/animation/Animator)!`)` Sets up the given animation to play at the same time as the animation supplied in the[AnimatorSet.play(Animator)](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet#play(android.animation.Animator))call that created this`Builder`object.                                                  |

## Public methods

### after

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun after(anim: Animator!): AnimatorSet.Builder!
```

Sets up the given animation to play when the animation supplied in the[AnimatorSet.play(Animator)](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet#play(android.animation.Animator))call that created this`Builder`object to start when the animation supplied in this method call ends.

|                                                                                                                                                        Parameters                                                                                                                                                         ||
|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `anim` | [Animator](https://developer.android.com/reference/kotlin/android/animation/Animator)!:The animation whose end will cause the animation supplied to the[AnimatorSet.play(Animator)](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet#play(android.animation.Animator))method to play. |

### after

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun after(delay: Long): AnimatorSet.Builder!
```

Sets up the animation supplied in the[AnimatorSet.play(Animator)](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet#play(android.animation.Animator))call that created this`Builder`object to play when the given amount of time elapses.

|                                                                            Parameters                                                                            ||
|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| `delay` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html):The number of milliseconds that should elapse before the animation starts. |

### before

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun before(anim: Animator!): AnimatorSet.Builder!
```

Sets up the given animation to play when the animation supplied in the[AnimatorSet.play(Animator)](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet#play(android.animation.Animator))call that created this`Builder`object ends.

|                                                                                                                                                      Parameters                                                                                                                                                       ||
|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `anim` | [Animator](https://developer.android.com/reference/kotlin/android/animation/Animator)!:The animation that will play when the animation supplied to the[AnimatorSet.play(Animator)](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet#play(android.animation.Animator))method ends. |

### with

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun with(anim: Animator!): AnimatorSet.Builder!
```

Sets up the given animation to play at the same time as the animation supplied in the[AnimatorSet.play(Animator)](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet#play(android.animation.Animator))call that created this`Builder`object.

|                                                                                                                                                       Parameters                                                                                                                                                        ||
|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `anim` | [Animator](https://developer.android.com/reference/kotlin/android/animation/Animator)!:The animation that will play when the animation supplied to the[AnimatorSet.play(Animator)](https://developer.android.com/reference/kotlin/android/animation/AnimatorSet#play(android.animation.Animator))method starts. |