实现RecyclerView下拉刷新和上拉加载更多以及RecyclerView线性、网格、瀑布流效果演示。如果你只需要简单地实现下拉刷新和上拉加载效果,不需要定制,那PullLoadMoreRecyclerView最适合不过。
dependencies {
compile 'com.wuxiaolong.pullloadmorerecyclerview:library:1.1.2'
}
<com.wuxiaolong.pullloadmorerecyclerview.PullLoadMoreRecyclerView
android:id="@+id/pullLoadMoreRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
mPullLoadMoreRecyclerView = (PullLoadMoreRecyclerView) view.findViewById(R.id.pullLoadMoreRecyclerView);
mPullLoadMoreRecyclerView.setLinearLayout();
mPullLoadMoreRecyclerView.setGridLayout(2);//参数为列数
mPullLoadMoreRecyclerView.setStaggeredGridLayout(2);//参数为列数
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);
}
}
}
mPullLoadMoreRecyclerView.setOnPullLoadMoreListener(new PullLoadMoreRecyclerView.PullLoadMoreListener() {
@Override
public void onRefresh() {
}
@Override
public void onLoadMore() {
}
});
mPullLoadMoreRecyclerView.setPullLoadMoreCompleted();
mPullLoadMoreRecyclerView.setRefreshing(true);
mPullLoadMoreRecyclerView.setPullRefreshEnable(false);
mPullLoadMoreRecyclerView.setPushRefreshEnable(false);
mPullLoadMoreRecyclerView.setFooterViewText("loading");
mPullLoadMoreRecyclerView.setFooterViewTextColor(R.color.white);
mPullLoadMoreRecyclerView.setFooterViewBackgroundColor(R.color.colorBackground);
mPullLoadMoreRecyclerView.setColorSchemeResources(android.R.color.holo_red_dark,android.R.color.holo_blue_dark);
mPullLoadMoreRecyclerView.scrollToTop();
我的微信公众号:吴小龙同学,欢迎关注交流。