[SOLVED] How do I chain together layout change animations with the LayoutTransition class or otherwise?


This Content is from Stack Overflow. Question asked by Adil Hussain

I have a ViewGroup on which I have set the android:animateLayoutChanges property to true.

As a result, when I toggle the visibility of one of the Views in the ViewGroup between View.VISIBLE to VIEW.GONE, I get a nice layout change animation as follows:

Animated layout changes

I’d like to take this idea a step further and chain together a sequence of transitions. For example, hide “Two” and then show “Three”.

How do I do this?


I have managed to achieve this as follows:

  1. Define a LayoutTransition.TransitionListener which sets the visibility of the View that I want to show as View.VISIBLE when the endTransition(…) method is called.
  2. Get the LayoutTransition object in the ViewGroup and add the LayoutTransition.TransitionListener defined in step 1 to it.
  3. Set the visibility of the View that I want to hide as View.GONE.

This achieves a sequence of animations as follows:

Animated layout changes

This works but seems a little fragile and is a somewhat clumsy solution for scenarios where I need to add a third or fourth animation to the sequence.

If anybody has suggestions for a simpler means of chaining together layout change animations, I’m open to it.


  1. My description of the implementation above is a little simplified and omits some work I’m doing to remove the LayoutTransition.TransitionListener when a given transition ends. For the concrete details, see here.

This Question was asked in StackOverflow by Adil Hussain and Answered by Adil Hussain It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?