转自 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使用
<com.andview.refreshview.XRefreshView
android:id="@+id/xrefreshview_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listViewcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</com.andview.refreshview.XRefreshView>
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<String,Object> 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<String,Object> 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
<?xml version="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="center"
android:orientation="vertical">
<com.operations.winsky.testxrfresugif.GifView
android:id="@+id/gif1"
android:layout_width="15dp"
android:layout_height="33dp"
android:layout_marginTop="10dp"
android:enabled="false" />
<com.operations.winsky.testxrfresugif.GifView
android:id="@+id/gif2"
android:layout_width="24dp"
android:layout_height="10dp"
android:layout_marginTop="10dp"
android:enabled="false" />
<TextView
android:id="@+id/gif_header_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/xrefreshview_header_hint_normal"
android:textColor="#222222" />
</LinearLayout>
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
<style name="Widget_GifView"parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particularAPI-level can go here. -->
</style>
<style name="AppBaseTheme"parent="android:Theme.Holo.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
5自定义头部动画 attrs.xml
<declare-styleablename="GifView">
<attr name="gif" format="reference" />
<attr name="paused" format="boolean" />
</declare-styleable>
<declare-styleable name="CustomTheme">
<attr name="gifViewStyle" format="reference"/>
</declare-styleable>
});
七别忘了加gif文件