Android的ExpandableListView使用动画 [英] Android ExpandableListView using animation

查看:887
本文介绍了Android的ExpandableListView使用动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用

<ExpandableListView
     android:id="@+id/listView"
     android:layout_width="match_parent"
     android:layout_height="match_parent" >
</ExpandableListView>

我想添加动画幻灯片的儿童在父母的onclick。所以,我该怎么办?

i want add animation slide for child when onclick parent . So How can i do ?

推荐答案

我其实不喜欢流行的实现,只需使用一个ListView与扩大动画的动画ExpandableListView的,因为在我的使用情况下,我的每个组有一个很多孩子,所以它并没有使用普通的ListView可行的,因为孩子的意见将不会被回收,内存使用量将是巨大的表现欠佳。相反,我用了一个更困难的,但更多的可扩展性和灵活的方法。

I actually do not like the popular implementation of an animated ExpandableListView that simply uses a ListView with an expand animation because in my use case, each of my groups had a lot of children, therefore it was not feasible to use a normal ListView as the child views will not be recycled and the memory usage will be huge with poor performance. Instead, I went with a much more difficult but more scalable and flexible approach.

我延长了ExpandableListView类,并覆盖了onCollapse和onExpand功能,我还创建了一个名为AnimatedExpandableListAdapter BaseExpandableListAdapter的子类。适配器里面,我重写了getChildView功能并取得了最终的功能,这样函数不能再次推翻。相反,我提供了一个名为getRealChildView子类覆盖,以提供一个真正的孩子另外一个功能。然后,我添加了一个动画标志类,并提出getChildView返回,如果动画已​​经设置一个虚拟的观点,如果没有设置标志的真正看法。现在,随着舞台布景我做的对onExpand以下内容:

I extended the ExpandableListView class and overrode the onCollapse and onExpand functions, I also created a subclass of a BaseExpandableListAdapter called AnimatedExpandableListAdapter. Inside the adapter, I overrode the getChildView function and made the function final so that the function cannot be overrode again. Instead I provided another function called getRealChildView for subclasses to override to provide a real child view. I then added an animation flag to the class and made getChildView return a dummy view if the animation flag was set and the real view if the flag was not set. Now with the stage set I do the following for onExpand:


  1. 设置在适配器动画标志,告诉哪个组正在扩大的适配器。

  2. 呼叫 notifyDataSetChanged()(强制适配器调用 getChildView()的屏幕上所有的观点)。

  3. 适配器(动画模式),然后创建一个不断扩大的团体有初始高度0.然后适配器将得到真正的孩子的意见,并通过这些意见到虚拟视图的虚拟视图。

  4. 的虚拟视图将然后开始绘制在它自己的真正的子视图的onDraw()功能。

  5. 适配器将揭开序幕动画循环,将扩大虚拟视图,直到它是正确的大小。它还将设置动画侦听器,这样一旦动画完成它可以清除动画标志并调用 notifyDataSetChanged()以及

  1. Set the animation flag in the adapter and tell the adapter which group is expanding.
  2. Call notifyDataSetChanged() (forces the adapter to call getChildView() for all views on screen).
  3. The adapter (in animation mode) will then create a dummy view for the expanding group that has initial height 0. The adapter will then get the real child views and pass these views to the dummy view.
  4. The dummy view will then start to draw the real child views within it's own onDraw() function.
  5. The adapter will kick off an animation loop that will expand the dummy view until it is of the right size. It will also set an animation listener so that it can clear the animation flag once the animation completes and will call notifyDataSetChanged() as well.

最后有了这一切完成后,我不仅能够得到想要的动画效果也有理想的表现,此方法将工作组拥有超过100名儿童。

Finally with all of this done, I was able to not only get the desired animation effect but also the desired performance as this method will work with group with over 100 children.

有关合拢动画,更多的工作需要做,以得到这一切的设置和运行。特别是,当你重写onCollapse,你不想调用父的功能,因为它会崩溃大队立即离开你没有机会去播放动画。相反,你要拨打super.onCollapse在合拢动画的结束。

For the collapsing animation, a little more work needs to be done to get this all setup and running. In particular, when you override onCollapse, you do not want to call the parent's function as it will collapse the group immediately leaving you no chance to play an animation. Instead you want to call super.onCollapse at the end of the collapse animation.

更新:

我花了一些时间在本周末重写我实施这一AnimatedExpandableListView和我解除与这里的用法示例源:
<一href=\"https://github.com/idunnololz/AnimatedExpandableListView/\">https://github.com/idunnololz/AnimatedExpandableListView/

I spent some time this weekend to rewrite my implementation of this AnimatedExpandableListView and I'm releasing the source with an example usage here: https://github.com/idunnololz/AnimatedExpandableListView/

这篇关于Android的ExpandableListView使用动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆