Issue
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:
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?
Solution
I have managed to achieve this as follows:
- 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.
- Get the LayoutTransition object in the ViewGroup and add the LayoutTransition.TransitionListener defined in step 1 to it.
- Set the visibility of the View that I want to hide as View.GONE.
This achieves a sequence of animations as follows:
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.
Notes
- 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.