网友通过本文主要向大家介绍了recyclerview下拉刷新,recyclerview下拉加载,recyclerview下拉,recyclerview实现分组,recyclerview实现画廊等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
RecyclerView 实现下拉刷新和自动加载,recyclerview下拉
RecyclerView是 Android 兼容包V21中新推出的列表类,它的自定义化强的优点足以让它能够取代GridView和ListView,本文将结合SwipeRefreshLayout与RecyclerView讲解如何实现下拉刷新和自动加载的代码
需要的依赖
以下版本自行更新
Java1 2 3 4 | compile 'com.android.support:appcompat-v7:21.0.0' compile 'com.android.support:recyclerview-v7:21.0.0' compile 'com.android.support:cardview-v7:21.0.0' compile 'com.android.support:support-v4:21.0.0' |
需要解决的问题
- [x] 下拉刷新
- [x] 自动加载
- [x] 网络请求异步加载
技术处理
下拉刷新
采用 android.support.v4.widget.SwipeRefreshLayout
来实现
具体可以搜索这个class,我们按照官方文档,布局如下
1 2 3 4 5 6 7 8 9 10 11 12 | <view xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/swipeRefreshLayout" class="android.support.v4.widget.SwipeRefreshLayout" android:layout_width="match_parent" android:layout_height="match_parent"> <view xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/recylerView" class="android.support.v7.widget.RecyclerView" android:layout_width="wrap_content" android:layout_height="wrap_content"></view> </view> |
然后对 swipeRefreshLayout
设置监听即可
1 2 3 4 5 6 7 8 9 10 | swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { if(isrefreshing){ Log.d(TAG,"ignore manually update!"); } else{ loadPage(); } } }); |
自动加载
RecyclerView是一个新兴事物,伸手党们还找不到 endless-RecyclerView
这样的开源神器,只好自己找方法了,同ListView一样,还是重写 OnScrollListener
这个方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
recyclerView.setOnScrollListener(
您可能想查找下面的文章:文章分类最近更新的内容
|