Android之带group指示器的ExpandableListView
Android之带group指示器的ExpandableListView
我们都知道Android缺省的ExpandableListView的group header无法固定在界面上,当向下滚动后,不能对当前显示的那些child 指示出它们归属于哪个group,在网上搜了很多关于仿手机QQ好友分组效果的ExpandableListView,发现都不尽如意,于是乎在别人的基础上改进了一点点,其实原理还是差不多的,只是增加了往上挤出去的动画效果,而且更加简单,只不过还是没有完全到达跟QQ一样的效果,希望有高手能实现更加逼真的效果,下面我们先看看效果图:
我这里没有把ExpandableListView独立出来形成一个新的控件,跟网上很多朋友一样,监听OnScrollListener事件,当group不是在第一个位置时,就把我们头部的那个indicator显示出来,并且让它的view跟当前child所在group的view一样的,然后再增加一个点击关闭组的事件,即达到了简单的仿QQ好友分组的效果。
下面我们先来看看主要的布局文件:main.xml,下面那个topGroup的FrameLayout就是我们的指示器。
- <?xmlversion="1.0"encoding="utf-8"?>
- <FrameLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <ExpandableListView
- android:id="@+id/expandableListView"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- </ExpandableListView>
- <FrameLayout
- android:id="@+id/topGroup"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
- </FrameLayout>
- </FrameLayout>
|
评论暂时关闭