Animation of height of LinearLayout container with ValueAnimator

Had some issues with animation in Android a couple of years ago and I posted the solution to StackOverflow. I thought I might post it here as well :)

Looking at chitgoks blog post I found that I shouldn’t use view.invalidate() to have the layout redrawn. I should use view.requestLayout().

Thus the code becomes something like this:

I just wanted to add a note on how to get the height of the LinearLayout as well to make the animation dynamic. To get the height all the views need to be drawn first. Therfor we have to listen for an event that tells us that the drawing is done. This can be done from the onResume() method like this (note that in my xml I have declared the container to wrap_content for height and it is also visible, since I want to hide it from the start I do that efter measuring it):