群里一哥们今天聊天偶然提到这个 git hub 上的控件:pull-to-refresh,有兴趣的看下,例子
中的功能极其强大,支持很多控件。本篇博客详细给大家介绍下 ListView 和 GridView 利用
pull-to-rerfesh 实现下拉刷新和上拉加载更多。
1、ListView 下拉刷新快速入门
pull-to-refresh 对 ListView 进行了封装,叫做:PullToRefreshListView,用法和 listview 没什
么区别,下面看 demo.
布局文件:
[html]view plain copy
1. <RelativeLayoutxmlns
:android="http://
schemas.android.com/
apk/res/android"
2. xmlns:tools="http
://
schemas.android.com/
tools"
3. android:layout_width="match_parent"
4. android:layout_height="match_parent">
5.
6. <com.handmark.pulltorefresh.library.PullToRefreshListView
7. xmlns:ptr="http://schemas.android.com/apk/res-auto"
8. android:id="@+id/pull_refresh_list"
9. android:layout_width="fill_parent"
10. android:layout_height="fill_parent"
11. android:cacheColorHint="#00000000"
12. android:divider="#19000000"
13. android:dividerHeight="4dp"
14. android:fadingEdge="none"
15. android:fastScrollEnabled="false"
16. android:footerDividersEnabled="false"
17. android:headerDividersEnabled="false"
18. android:smoothScrollbar="true">
19. </com.handmark.pulltorefresh.library.PullToRefreshListView>
20.
21. </RelativeLayout>
声明了一个 PullToRefreshListView,里面所有的属性都是 ListView 的,没有任何其他
属性,当然了 PullToRefreshListView 也提供了很多配置的属性,后面会详细介绍。