Most expand and collapse animation code I saw in Android related forums never worked. I think that they probably are limited to just widgets. When the View object itself e.g. LinearLayout has children within it, then those animation XMLs or code to animate them during runtime do not work.

The closest code that worked is from Tom Esterez. He describes it as a dirty hack but I think that it is the only code that is shared publicly that works. However, the code he shared is limited to expanding the ViewGroup.

I modified his existing code to also cater a collapse version. The method returns Animation object.

Feel free to change the animation speed according to your preference. The lower the value, the faster the animation speed will be.

Expand the code area section to view the method in full.

Related Posts Plugin for WordPress, Blogger...