XRecyclerView的使用



项目地址https://github.com/jianghejie/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

public class Main2Activity extends AppCompatActivity {
    XRecyclerView recyclerView;
    List<Integer> data=new ArrayList<Integer>();
    MyAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        recyclerView=(XRecyclerView)findViewById(R.id.xrecy);
        LinearLayoutManager xLinearLayoutManager = new LinearLayoutManager(this);
        //xLinearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(xLinearLayoutManager);
        View header= LayoutInflater.from(this).inflate(R.layout.header,null);
        recyclerView.addHeaderView(header);     //添加头部
        recyclerView.setRefreshProgressStyle(ProgressStyle.BallZigZag); //设定下拉刷新样式
        recyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallZigZag);//设定上拉加载样式
        recyclerView.setArrowImageView(R.drawable.qwe);     //设定下拉刷新显示图片(不必须)
        initData();   //初始化数据
        adapter=new MyAdapter(data);
        recyclerView.setAdapter(adapter);
        /**
         *设定下拉刷新和上拉加载监听
         */
        recyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            //上拉加载监听
            @Override
            public void onLoadMore() {
                addData();  //上拉加载添加数据
                recyclerView.loadMoreComplete();    //加载数据完成(取消加载动画)
            };
            //下拉刷新监听
            @Override
            public void onRefresh() {
                initData();     //初始化数据
                adapter.notifyDataSetChanged();
                recyclerView.refreshComplete();     //刷新数据完成(取消刷新动画)
            }
        });
    }

    /**
     *上拉加载添加数据
     */
    private void addData() {
        for (int i=0;i<20;i++){
            Integer r= Integer.valueOf((int) (Math.random()*100));
            data.add(r);
        }
        adapter.notifyDataSetChanged();
    }

    /**
     *初始化数据
     */
    private void initData() {
        data.clear();
        for (int i=0;i<40;i++){
            Integer r= Integer.valueOf(i);
            data.add(r);
        }
    }
}


MyAdapter

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
    List<Integer> data=new ArrayList<Integer>();
    static class MyViewHolder extends RecyclerView.ViewHolder{
        TextView textView;
        public MyViewHolder(View itemView) {
            super(itemView);
            this.textView=itemView.findViewById(R.id.item_text);
        }
    }

    public MyAdapter(List<Integer> data) {
        super();
        this.data=data;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item,null);
        MyViewHolder myViewHolder=new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        Integer da=data.get(position);
        holder.textView.setText(da+"");
    }

    @Override
    public int getItemCount() {
        return data.size();
    }
}



  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值