Add animation to an ExpandableListView

user430926 picture user430926 · Mar 16, 2012 · Viewed 19.1k times · Source

Is there a way to add animation when opening an expandable list in Android? I want it so that when the user clicks on the expandable list, it has an animation/effect like I'm opening a sliding drawer.

It moves slow until it is completely opened.

Answer

Dmitry Zaytsev picture Dmitry Zaytsev · Dec 8, 2012

I've spent a lot of time searching with no luck. The existing solutions are just not smooth enough - if your layout is something more complex than just 2 buttons, it becomes laggy.

So, I've created my own ListAdapter that caches the whole view into a Bitmap and then performs the animation on the cached view instead of the view itself. It works much faster.

Here it is: https://github.com/dmitry-zaitsev/ExpandableAdapter

The good news is that you don't need to rewrite a bunch of code - just wrap my ExpandableAdapter around your adapter and provide the id of the view that will act like a toggle button and the id of the view that holds the content of the second level:

new ExpandableAdapter(context, yourAdapter, R.id.switch, R.id.holder);

And that is all.