吴小龙同學

PullLoadMoreRecyclerView

实现RecyclerView下拉刷新和上拉加载更多以及RecyclerView线性、网格、瀑布流效果演示

效果预览


实例APP

魅族应用商店

使用方法

build.gradle文件

1
2
3
dependencies {
compile 'com.wuxiaolong.pullloadmorerecyclerview:library:1.0.3'
}

xml引用

1
2
3
4
5
<com.wuxiaolong.pullloadmorerecyclerview.PullLoadMoreRecyclerView
android:id="@+id/pullLoadMoreRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp" />

设置线性布局

1
2
mPullLoadMoreRecyclerView = (PullLoadMoreRecyclerView) view.findViewById(R.id.pullLoadMoreRecyclerView);
mPullLoadMoreRecyclerView.setLinearLayout();

设置网格布局

1
mPullLoadMoreRecyclerView.setGridLayout(2);//参数为列数

设置交错网格布局,即瀑布流效果

1
mPullLoadMoreRecyclerView.setStaggeredGridLayout(2);//参数为列数

绑定适配器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
mRecyclerViewAdapter = new RecyclerViewAdapter();
mPullLoadMoreRecyclerView.setAdapter(mRecyclerViewAdapter);
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
public RecyclerViewAdapter() {
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_view_item, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
}
@Override
public int getItemCount() {
return 0;
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(View itemView) {
super(itemView);
}
}
}

调用下拉刷新和加载更多

1
2
3
4
5
6
7
8
9
10
11
mPullLoadMoreRecyclerView.setOnPullLoadMoreListener(new PullLoadMoreRecyclerView.PullLoadMoreListener() {
@Override
public void onRefresh() {
}
@Override
public void onLoadMore() {
}
});

刷新结束

1
mPullLoadMoreRecyclerView.setPullLoadMoreCompleted();

其他方法

不需要下拉刷新

1
mPullLoadMoreRecyclerView.setPullRefreshEnable(false);

设置下拉刷新颜色

1
mPullLoadMoreRecyclerView.setColorSchemeResources(android.R.color.holo_red_dark,android.R.color.holo_blue_dark);

快速Top

1
mPullLoadMoreRecyclerView.scrollToTop();

源码地址

PullLoadMoreRecyclerView

更多交流

Android技术交流群
③群:370527306剩者为王③群

个人博客

http://wuxiaolong.me/

作者微博

吴小龙同學

License

Apache 2.0



联系我

我的微信公众号:吴小龙同学,欢迎关注交流~

赞助商:躲角落的猫咪