BeautifulRefreshLayout:里面包含了坐着收集的一些下拉刷新的控件
另一个
XRecyclerView地址(这个可以自定义下拉动画样式)https://github.com/dalu9527/XRecyclerView
一个RecyclerView,它实现了pullrefresh,loadmore和header featrues.you可以像标准的RecyclerView一样使用它。你不需要实现一个特殊的适配器.qq群478803619截图
用法
##gradle
compile 'com.jcodecraeer:xrecyclerview:1.3.2'
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); layoutManager 。setOrientation(LinearLayoutManager 。 VERTICAL); mRecyclerView 。setLayoutManager(的layoutManager); mRecyclerView 。setAdapter(mAdapter);
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](https://github.com/jianghejie/XRecyclerView/raw/master/art/refreshloadingballspinfade.gif)
mRecyclerView.setLaodingMoreProgressStyle(ProgressStyle.SquareSpin);
BallPulse effect
所有的效果都可以在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; }
刷新箭头图标
我们提供一个默认的箭头图标:
但是如果你不喜欢它,你可以用任何你想要的其他图标替换它。
mRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey);
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);
- }
- }
- }
- 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();
- }
- }