一个提供上拉刷新,下拉加载更多,显示状态页(错误、空、加载中)的RecyclerView,且加载更多样式、状态页样式均可自定义,可直接在xml配置线性布局还是网格布局,以及网格布局的列个数 该项目参考了此项目 https://github.com/YougaKing/DragRecyclerView 与其说参考,不如说是再封装了一次,以及改了部分内容
使用方法:
compile 'com.chn.srecyclerview:SRecyclerView:0.1'
xml里面直接引用:
默认为LinearLayoutManager VERTICAL 的样式 <com.chn.srecyclerview.SRecyclerView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ac_sample_srv" android:layout_width="match_parent" android:layout_height="match_parent" />
设置网格样式 <com.chn.srecyclerview.SRecyclerView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/ac_sample_srv" android:layout_width="match_parent" android:layout_height="match_parent" app:srv_layoutManager="GridLayout" app:srv_spanCount="3" />
设置网格,且加载完成后有“已经到底了”的字样 <com.chn.srecyclerview.SRecyclerView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/ac_sample_srv" android:layout_width="match_parent" android:layout_height="match_parent" app:srv_layoutManager="GridLayout" app:srv_showOver="true" app:srv_spanCount="3" />
具体的自定义属性
代码中调用 设置Adapter: sRecyclerView.setAdapter(myAdapter); 设置监听:sRecyclerView.setOnRequestListener(new SRecyclerView.OnRequestListener() { @Override public void onRefresh() {
}
@Override
public void onLoadMore() {
}
@Override
public void onStateClick() {
}
});
网络访问结束后,如果没有网络原因,更新自己的adapter,再调用sRecyclerView.setHadNextPage(true); true表示有下一页 如果有网络原因,可以直接调用 sRecyclerView.requestFail();内部会判断最近的一次请求是下拉刷新还是加载更多还是点击错误页面发出的 也可以自己调用 refreshFail(); loadMoreFail(); stateFail();