XRecyclerView的使用(参数)

BeautifulRefreshLayout:里面包含了坐着收集的一些下拉刷新的控件
另一个 XRecyclerView地址(这个可以自定义下拉动画样式)https://github.com/dalu9527/XRecyclerView



一个RecyclerView,它实现了pullrefresh,loadmore和header featrues.you可以像标准的RecyclerView一样使用它。你不需要实现一个特殊的适配器.qq群478803619截图

演示

用法

##gradle

compile 'com.jcodecraeer:xrecyclerview:1.3.2'
就像一个标准的RecyclerView

LinearLayoutManager layoutManager =  new  LinearLayoutManager(getActivity());
layoutManager setOrientation(LinearLayoutManager  VERTICAL);
mRecyclerView setLayoutManager(的layoutManager);
mRecyclerView setAdapter(mAdapter);


## 刷新和加载更多功能默认启用。 我们提供一个回调来触发刷新和LoadMore事件。

mRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
    @Override
    public void onRefresh() {
       //refresh data here
    }

    @Override
    public void onLoadMore() {
       // load more data here
    }
});

当然,当您刷新或加载更多的工作完成时,您必须告诉我们的RecyclerView。您可以使用

mRecyclerView.loadMoreComplete();
通知加载更多的工作完成。

mRecyclerView.refreshComplete();
通知刷新工作完成。

这是我们得到的:

默认

##调用refresh()手动刷新

mRecyclerView.refresh();

###自定义刷新和加载更多样式拉刷和加载更多的风格是高度可定制的。

我们使用AVLoadingIndicatorView的加载效果 它是内置的(做一点变化)。除了添加系统风格,我们还提供了AVLoadingIndicatorView库中的所有效果。

mRecyclerView.setRefreshProgressStyle(int style);

mRecyclerView.setLaodingMoreProgressStyle(int style);
分别设置RefreshProgressStyle和LaodingMoreProgressStyle。

例如:

mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
refreshloadingballspinfade

mRecyclerView.setLaodingMoreProgressStyle(ProgressStyle.SquareSpin);

loadingmoresquarespin

BallPulse effect

BallPulse


所有的效果都可以在ProgressStyle类中获得

public class ProgressStyle {
    public static final int SysProgress=-1;
    public static final int BallPulse=0;
    public static final int BallGridPulse=1;
    public static final int BallClipRotate=2;
    public static final int BallClipRotatePulse=3;
    public static final int SquareSpin=4;
    public static final int BallClipRotateMultiple=5;
    public static final int BallPulseRise=6;
    public static final int BallRotate=7;
    public static final int CubeTransition=8;
    public static final int BallZigZag=9;
    public static final int BallZigZagDeflect=10;
    public static final int BallTrianglePath=11;
    public static final int BallScale=12;
    public static final int LineScale=13;
    public static final int LineScaleParty=14;
    public static final int BallScaleMultiple=15;
    public static final int BallPulseSync=16;
    public static final int BallBeat=17;
    public static final int LineScalePulseOut=18;
    public static final int LineScalePulseOutRapid=19;
    public static final int BallScaleRipple=20;
    public static final int BallScaleRippleMultiple=21;
    public static final int BallSpinFadeLoader=22;
    public static final int LineSpinFadeLoader=23;
    public static final int TriangleSkewSpin=24;
    public static final int Pacman=25;
    public static final int BallGridBeat=26;
    public static final int SemiCircleSpin=27;
}
刷新箭头图标

我们提供一个默认的箭头图标:

ic_pulltorefresh_arrow

但是如果你不喜欢它,你可以用任何你想要的其他图标替换它。

mRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey);

customarrow

###禁用刷新并加载更多功能,如果你不想刷新和加载更多的功能,你可以调用

mRecyclerView.setPullRefreshEnabled(false);

mRecyclerView.setPullRefreshEnabled(true);
其中false表示禁用,true表示启用。

##头可以添加头到XRecyclerView,只需调用addHeaderView()。

View header =   LayoutInflater.from(this).inflate(R.layout.recyclerview_header, (ViewGroup)findViewById(android.R.id.content),false);
mRecyclerView.addHeaderView(header);
如果你喜欢,你可以添加两个标题

View header =   LayoutInflater.from(this).inflate(R.layout.recyclerview_header, (ViewGroup)findViewById(android.R.id.content),false);
View header1 =   LayoutInflater.from(this).inflate(R.layout.recyclerview_header1, (ViewGroup)findViewById(android.R.id.content),false);
mRecyclerView.addHeaderView(header);
mRecyclerView.addHeaderView(header1);


demo

MainActivity

[java]  view plain  copy
  1. public class Main2Activity extends AppCompatActivity {  
  2.     XRecyclerView recyclerView;  
  3.     List<Integer> data=new ArrayList<Integer>();  
  4.     MyAdapter adapter;  
  5.   
  6.     @Override  
  7.     protected void onCreate(Bundle savedInstanceState) {  
  8.         super.onCreate(savedInstanceState);  
  9.         setContentView(R.layout.activity_main2);  
  10.         recyclerView=(XRecyclerView)findViewById(R.id.xrecy);  
  11.         LinearLayoutManager xLinearLayoutManager = new LinearLayoutManager(this);  
  12.         //xLinearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);  
  13.         recyclerView.setLayoutManager(xLinearLayoutManager);  
  14.         View header= LayoutInflater.from(this).inflate(R.layout.header,null);  
  15.         recyclerView.addHeaderView(header);     //添加头部  
  16.         recyclerView.setRefreshProgressStyle(ProgressStyle.BallZigZag); //设定下拉刷新样式  
  17.         recyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallZigZag);//设定上拉加载样式  
  18.         recyclerView.setArrowImageView(R.drawable.qwe);     //设定下拉刷新显示图片(不必须)  
  19.         initData();   //初始化数据  
  20.         adapter=new MyAdapter(data);  
  21.         recyclerView.setAdapter(adapter);  
  22.         /** 
  23.          *设定下拉刷新和上拉加载监听 
  24.          */  
  25.         recyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {  
  26.             //上拉加载监听  
  27.             @Override  
  28.             public void onLoadMore() {  
  29.                 addData();  //上拉加载添加数据  
  30.                 recyclerView.loadMoreComplete();    //加载数据完成(取消加载动画)  
  31.             };  
  32.             //下拉刷新监听  
  33.             @Override  
  34.             public void onRefresh() {  
  35.                 initData();     //初始化数据  
  36.                 adapter.notifyDataSetChanged();  
  37.                 recyclerView.refreshComplete();     //刷新数据完成(取消刷新动画)  
  38.             }  
  39.         });  
  40.     }  
  41.   
  42.     /** 
  43.      *上拉加载添加数据 
  44.      */  
  45.     private void addData() {  
  46.         for (int i=0;i<20;i++){  
  47.             Integer r= Integer.valueOf((int) (Math.random()*100));  
  48.             data.add(r);  
  49.         }  
  50.         adapter.notifyDataSetChanged();  
  51.     }  
  52.   
  53.     /** 
  54.      *初始化数据 
  55.      */  
  56.     private void initData() {  
  57.         data.clear();  
  58.         for (int i=0;i<40;i++){  
  59.             Integer r= Integer.valueOf(i);  
  60.             data.add(r);  
  61.         }  
  62.     }  
  63. }  


MyAdapter

[java]  view plain  copy
  1. public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {  
  2.     List<Integer> data=new ArrayList<Integer>();  
  3.     static class MyViewHolder extends RecyclerView.ViewHolder{  
  4.         TextView textView;  
  5.         public MyViewHolder(View itemView) {  
  6.             super(itemView);  
  7.             this.textView=itemView.findViewById(R.id.item_text);  
  8.         }  
  9.     }  
  10.   
  11.     public MyAdapter(List<Integer> data) {  
  12.         super();  
  13.         this.data=data;  
  14.     }  
  15.   
  16.     @Override  
  17.     public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {  
  18.         View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item,null);  
  19.         MyViewHolder myViewHolder=new MyViewHolder(view);  
  20.         return myViewHolder;  
  21.     }  
  22.   
  23.     @Override  
  24.     public void onBindViewHolder(MyViewHolder holder, int position) {  
  25.         Integer da=data.get(position);  
  26.         holder.textView.setText(da+"");  
  27.     }  
  28.   
  29.     @Override  
  30.     public int getItemCount() {  
  31.         return data.size();  
  32.     }  
  33. }  
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值