【开源】pinned-section-listview

pinned-section-listview

 

介绍:

在很多应用中,看到这样的listview:listview滑动过程中分组标题固定在上方,当第二个组滑上来时,第一个组才跟着上滑,下一个组固定,直到该组也滑出上边缘。世上无难事只怕有心人,在github上就有人做出来了,而且效果很好(后来发现安卓自带应用中联系人应用就是这样的,估计github的作者也是仿照着联系人做出来的吧)。 与其他实现类似功能的代码不同PinnedSectionListView直接继承自ListView。

运行效果:

 

 

使用说明:

1.在xml布局文件中将ListView替换成PinnedSectionListView

<com.hb.views.PinnedSectionListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />

  2.让你的ListAdapter继承PinnedSectionListAdapter接口,最简单的做法是只增加isItemViewTypePinned方法,该方法必须在item为pinned的情况下返回true。

 

// Our adapter class implements 'PinnedSectionListAdapter' interface
class MyPinnedSectionListAdapter extends BaseAdapter implements PinnedSectionListAdapter {
     ...
     // We implement this method to return 'true' for all view types we want to pin
     @Override
     public boolean isItemViewTypePinned(int viewType) {
         return viewType == <type to be pinned>;
     }
}

  

posted on 2015-03-23 16:16  wasdchenhao  阅读(255)  评论(0)    收藏  举报

导航