XRefreshView集成以及自定义GIF动画
1继承第三方库
compile 'com.huxq17.xrefreshview:xrefreshview:3.6.9'
//依赖下面的库不然会报错
compile 'com.android.support:recyclerview-v7:23.0.1'
2项目xml使用
android:id="@+id/xrefreshview_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/listViewcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
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.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.put("userId", UseBeanUtils.getData(context).getId());
// map.put("page", pageNum + "");
// map.put("size", "10");
// repairOrderView.repairOrderxRefreshView(map, xRefreshView,
aBooleanLoad);
xRefreshView.stopLoadMore();
}
}, 2000);
}
3配置 GifViewXml
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="center"
android:orientation="vertical">
android:id="@+id/gif1"
android:layout_width="15dp"
android:layout_height="33dp"
android:layout_marginTop="10dp"
android:enabled="false" />
android:id="@+id/gif2"
android:layout_width="24dp"
android:layout_height="10dp"
android:layout_marginTop="10dp"
android:enabled="false" />
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" />
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文件