Add animation to an ExpandableListView

前端 未结 5 1635
星月不相逢
星月不相逢 2021-02-08 05:44

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 o

5条回答
  •  时光说笑
    2021-02-08 06:23

    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.

提交回复
热议问题