2018-09-13 XRefreshView 下拉刷新

转自 https://blog.csdn.net/u013297881/article/details/76618395 整理一下

1继承第三方库

// 依赖下面的库不然会报错
compile 'com.huxq17.xrefreshview:xrefreshview:3.6.9'
compile 'com.android.support:recyclerview-v7:23.0.1'

2项目xml使用



 

       

   

3配置 xRefreshView文件

CustomGifHeader header = new CustomGifHeader(this);

       CustomFooterView customFooterView=new CustomFooterView(this);

       xRefreshView.setCustomHeaderView(header);

       xRefreshView.setCustomFooterView(customFooterView);

       //设置是否可以下拉刷新

       xRefreshView.setPullRefreshEnable(true);

       //设置是否可以上拉加载

       xRefreshView.setPullLoadEnable(true);

       xRefreshView.setMoveForHorizontal(true);

       xRefreshView.setAutoLoadMore(false);

       xRefreshView.setPinnedTime(1000);

       xRefreshView.setXRefreshViewListener(newXRefreshView.SimpleXRefreshListener() {

           @Override

           public void onRefresh(boolean isPullDown) {

               new Handler().postDelayed(newRunnable() {

                   @Override

                   public void run() {

                      

//                       pageNum = 1;

//                       aBooleanLoad = false;

//                       Map map = new HashMap<>();

//                       map.put("userId", UseBeanUtils.getData(context).getId());

//                       map.put("page", pageNum + "");

//                       map.put("size", "10");

//                 


      repairOrderView.repairOrderxRefreshView(map, xRefreshView, aBooleanLoad);
 
                       xRefreshView.stopRefresh();

                   }

               }, 2000);

           }
 
           @Override

           public void onLoadMore(boolean isSilence) {

               new Handler().postDelayed(newRunnable() {
 
                   @Override

                   public void run() { 
//                       pageNum = pageNum + 1;

//                       aBooleanLoad = true;

//                       Map map = new HashMap<>();

//                       map.put("userId", UseBeanUtils.getData(context).getId());

//                       map.put("page", pageNum + "");

//                       map.put("size", "10");

//                       repairOrderView.repairOrderxRefreshView(map, xRefreshView,

aBooleanLoad);

                     

                       xRefreshView.stopLoadMore();

                   }

               }, 2000);

           } 


3配置 GifViewXml





 

   

 

   

 

   

 



 

4自定义头部动画


packagecom.operations.winsky.testxrfresugif;

 

import android.content.Context;

import android.graphics.Color;

import android.util.AttributeSet;

import android.view.LayoutInflater;

import android.view.View;

import android.widget.LinearLayout;

import android.widget.TextView;

 

importcom.andview.refreshview.callback.IHeaderCallBack;

 

 

public class CustomGifHeader extendsLinearLayout implements IHeaderCallBack {

   private GifView gifView1;

   private GifView gifView2;

   privateTextView mHintTextView;

 

   public CustomGifHeader(Context context) {

       super(context);

       setBackgroundColor(Color.parseColor("#f3f3f3"));

       initView(context);

   }

 

   /**

    * @param context

    * @param attrs

    */

   publicCustomGifHeader(Context context, AttributeSet attrs) {

       super(context, attrs);

       initView(context);

   }

 

   private void initView(Context context) {

       LayoutInflater.from(context).inflate(R.layout.gif_header, this);

       gifView1 = (GifView) findViewById(R.id.gif1);

       mHintTextView = (TextView) findViewById(R.id.gif_header_hint);

       gifView2 = (GifView) findViewById(R.id.gif2);

       gifView1.setMovieResource(R.raw.vertical);

       gifView2.setMovieResource(R.raw.horizontal);

       gifView2.setVisibility(View.GONE);

   }

 

   public void setRefreshTime(long lastRefreshTime) {

   }

 

   public void hide() {

       setVisibility(View.GONE);

   }

 

   public void show() {

       setVisibility(View.VISIBLE);

   }

 

   @Override

   public void onStateNormal() {

       mHintTextView.setText(R.string.xrefreshview_header_hint_normal);

       gifView1.setVisibility(View.VISIBLE);

       gifView2.setVisibility(View.GONE);

       gifView1.setPaused(false);

       gifView2.setPaused(true);

   }

 

   @Override

   public void onStateReady() {

       mHintTextView.setText(R.string.xrefreshview_header_hint_ready);

   }

 

   @Override

   public void onStateRefreshing() {

       mHintTextView.setText(R.string.xrefreshview_header_hint_refreshing);

       gifView1.setVisibility(View.GONE);

       gifView2.setVisibility(View.VISIBLE);

       gifView1.setPaused(true);

       gifView2.setPaused(false);

   }

 

   @Override

   public void onStateFinish(boolean success) {

       mHintTextView.setText(success ? R.string.xrefreshview_header_hint_loaded: R.string.xrefreshview_header_hint_loaded_fail);

//       gifView1.setVisibility(View.VISIBLE);

       gifView2.setVisibility(View.GONE);

       gifView2.setPaused(true);

   }

 

   @Override

   public void onHeaderMove(double headerMovePercent, int offsetY, intdeltaY) {

       //

   }

 

   @Override

   public int getHeaderHeight() {

       return getMeasuredHeight();

   }

}

5自定义头部动画style.xml



   

5自定义头部动画 attrs.xml

 

       

       

   

 

   

       

   

       });

七别忘了加gif文件




你可能感兴趣的:(2018-09-13 XRefreshView 下拉刷新)