1.引入下拉刷新庫
compile 'cn.bingoogolapple:bga-refreshlayout:1.1.7@aar'
項目中引入的其他庫
compile 'com.android.support:recyclerview-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.android.support:cardview-v7:25.0.1'
//輪播圖使用
compile 'cn.bingoogolapple:bga-banner:2.1.4@aar'
//可以添加header和footer的超級adapter
compile 'cn.bingoogolapple:bga-adapter:1.1.5@aar'
//類似QQ的滑動Item滑動側(cè)滑菜單
compile 'cn.bingoogolapple:bga-swipeitemlayout:1.0.4@aar'
//指示器
compile 'cn.bingoogolapple:bga-indicator:1.0.1@aar'
//retrofit
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'cn.pedant.sweetalert:library:1.3'
//glide圖片加載器
compile 'com.github.bumptech.glide:glide:3.7.0'
2.新建BGAYaTangRefreshViewHolder 繼承庫文件的抽象類BGARefreshViewHolder
實現(xiàn)其父類的帶參數(shù)的構(gòu)造方法和7個抽象方法,重寫getLoadMoreFooterView()和getRefreshHeaderView()實現(xiàn)自定義的頭部的底部
package cn.bingoogolapple.refreshlayout.demo.asmewill;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;
import cn.bingoogolapple.refreshlayout.BGARefreshViewHolder;
import cn.bingoogolapple.refreshlayout.demo.R;
/**
* Created by shuij on 2017/11/11 0011.
*/
public class BGAYaTangRefreshViewHolder extends BGARefreshViewHolder {
private TextView mHeaderStatusTv;
private String mPullDownRefreshText = "下拉刷新";
private String mReleaseRefreshText = "松開刷新";
private String mRefreshingText = "正在刷新...";
private boolean mIsLoadingMoreEnabled = true;
/**
* 整個加載更多控件的背景顏色資源id
*/
private int mLoadMoreBackgroundColorRes = -1;
/**
* 整個加載更多控件的背景drawable資源id
*/
private int mLoadMoreBackgroundDrawableRes = -1;
/**
* @param context
* @param isLoadingMoreEnabled 上拉加載更多是否可用
*/
public BGAYaTangRefreshViewHolder(Context context, boolean isLoadingMoreEnabled) {
super(context, isLoadingMoreEnabled);
}
/****
* 重新自定義FooterView
* @return
*/
@Override
public View getRefreshHeaderView() {
if (mRefreshHeaderView == null) {
mRefreshHeaderView = View.inflate(mContext, R.layout.refresh_head, null);
mRefreshHeaderView.setBackgroundColor(mContext.getResources().getColor(R.color.Cf2f2f5));
if (mRefreshViewBackgroundColorRes != -1) {
mRefreshHeaderView.setBackgroundResource(mRefreshViewBackgroundColorRes);
}
if (mRefreshViewBackgroundDrawableRes != -1) {
mRefreshHeaderView.setBackgroundResource(mRefreshViewBackgroundDrawableRes);
}
mHeaderStatusTv = (TextView) mRefreshHeaderView.findViewById(R.id.tipTextView);
mHeaderStatusTv.setText(mPullDownRefreshText);
}
return mRefreshHeaderView;
}
/****
* 重新自定義FooterView
* @return
*/
@Override
public View getLoadMoreFooterView() {
if (!mIsLoadingMoreEnabled) {
return null;
}
if (mLoadMoreFooterView == null) {
mLoadMoreFooterView = View.inflate(mContext, R.layout.listview_footer, null);
mLoadMoreFooterView.setBackgroundColor(Color.TRANSPARENT);
if (mLoadMoreBackgroundColorRes != -1) {
mLoadMoreFooterView.setBackgroundResource(mLoadMoreBackgroundColorRes);
}
if (mLoadMoreBackgroundDrawableRes != -1) {
mLoadMoreFooterView.setBackgroundResource(mLoadMoreBackgroundDrawableRes);
}
mFooterStatusTv = (TextView) mLoadMoreFooterView.findViewById(R.id.tv_load);
mFooterStatusTv.setText("拼命"+mLodingMoreText);
}
return mLoadMoreFooterView;
}
@Override
public void handleScale(float scale, int moveYDistance) {
}
@Override
public void changeToIdle() {
}
@Override
public void changeToPullDown() {
mHeaderStatusTv.setText(mPullDownRefreshText);
}
@Override
public void changeToReleaseRefresh() {
mHeaderStatusTv.setText(mReleaseRefreshText);
}
@Override
public void changeToRefreshing() {
mHeaderStatusTv.setText(mRefreshingText);
}
@Override
public void onEndRefreshing() {
mHeaderStatusTv.setText(mPullDownRefreshText);
}
/***
* 設(shè)置刷新提示語句
* @param mRefreshingText
*/
public void setmRefreshingText(String mRefreshingText) {
this.mRefreshingText = mRefreshingText;
}
public void setmPullDownRefreshText(String mPullDownRefreshText) {
this.mPullDownRefreshText = mPullDownRefreshText;
}
public void setmReleaseRefreshText(String mReleaseRefreshText) {
this.mReleaseRefreshText = mReleaseRefreshText;
}
/***
* 設(shè)置控件的背景資源id
* @param mLoadMoreBackgroundColorRes
*/
public void setmLoadMoreBackgroundColorRes(int mLoadMoreBackgroundColorRes) {
this.mLoadMoreBackgroundColorRes = mLoadMoreBackgroundColorRes;
}
public void setmLoadMoreBackgroundDrawableRes(int mLoadMoreBackgroundDrawableRes) {
this.mLoadMoreBackgroundDrawableRes = mLoadMoreBackgroundDrawableRes;
}
}
3.使用方法主要代碼如下:
BGAYaTangRefreshViewHolder bgaYaTangRefreshViewHolder=new BGAYaTangRefreshViewHolder(mApp,true);
bgaYaTangRefreshViewHolder.setPullDistanceScale(3.0f);
bgaYaTangRefreshViewHolder.setSpringDistanceScale(1.0f);
mRefreshLayout.setRefreshViewHolder(bgaYaTangRefreshViewHolder);
mDataLv.setAdapter(mAdapter);
xml文件:
<cn.bingoogolapple.refreshlayout.BGARefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/refreshLayout"
style="@style/MatchMatch"
android:paddingBottom="@dimen/test_padding_margin"
android:paddingTop="@dimen/test_padding_margin"
android:background="@color/Cf2f2f5">
<cn.bingoogolapple.refreshlayout.BGAStickyNavLayout
style="@style/MatchAuto"
android:layout_marginBottom="@dimen/test_padding_margin"
android:layout_marginTop="@dimen/test_padding_margin"
android:background="@color/test_spacing2"
android:paddingBottom="@dimen/test_padding_margin"
android:paddingTop="@dimen/test_padding_margin">
<TextView
style="@style/MatchWrap"
android:layout_marginBottom="@dimen/test_padding_margin"
android:layout_marginTop="@dimen/test_padding_margin"
android:background="@color/test_spacing3"
android:gravity="center"
android:paddingBottom="50dp"
android:paddingTop="50dp"
android:text="頂部視圖"
android:textColor="@android:color/white"
android:textSize="30sp" />
<LinearLayout
style="@style/MatchWrap.Horizontal"
android:layout_marginBottom="@dimen/test_padding_margin"
android:layout_marginTop="@dimen/test_padding_margin"
android:background="@color/colorPrimary"
android:paddingBottom="5dp"
android:paddingTop="5dp">
<TextView
android:id="@+id/retweet"
style="@style/AutoWrap"
android:gravity="center"
android:text="轉(zhuǎn)發(fā)"
android:textColor="@android:color/white"
android:textSize="14sp" />
<TextView
android:id="@+id/comment"
style="@style/AutoWrap"
android:gravity="center"
android:text="評論"
android:textColor="@android:color/white"
android:textSize="14sp" />
<TextView
android:id="@+id/praise"
style="@style/AutoWrap"
android:gravity="center"
android:text="贊"
android:textColor="@android:color/white"
android:textSize="14sp" />
</LinearLayout>
<ListView
android:id="@+id/data"
style="@style/MatchMatch"
android:layout_marginBottom="@dimen/test_padding_margin"
android:layout_marginTop="@dimen/test_padding_margin"
android:background="@android:color/white"
android:divider="@mipmap/list_divider"
android:overScrollMode="never"
android:paddingBottom="@dimen/test_padding_margin"
android:paddingTop="@dimen/test_padding_margin"
android:scrollbars="none"
tools:listitem="@layout/item_normal" />
</cn.bingoogolapple.refreshlayout.BGAStickyNavLayout>
</cn.bingoogolapple.refreshlayout.BGARefreshLayout>
4.自定義效果圖如下:
4.1自定義雅堂金融下拉樣式頭部刷新樣式
4.1自定義雅堂金融上啦加載樣式