BGARefreshLayout扩展自定义添加Header和Footer

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滑动侧滑菜单
    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

实现其父类的带参数的构造方法和7个抽象方法,重写getLoadMoreFooterView()和getRefreshHeaderView()实现自定义的头部的底部



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);

    }

    /***
     * 设置刷新提示语句
     * @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;
    }

    /***
     * 设置控件的背景资源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文件:



    

        

        

            

            

            
        

        

    

4.自定义效果图如下:

4.1自定义雅堂金融下拉样式头部刷新样式

BGARefreshLayout扩展自定义添加Header和Footer_第1张图片
图片.png

4.1自定义雅堂金融上啦加载样式
BGARefreshLayout扩展自定义添加Header和Footer_第2张图片
图片.png

5.代码参考地址:

https://github.com/Asmewill/BGARefreshLayout-Android-master

你可能感兴趣的:(BGARefreshLayout扩展自定义添加Header和Footer)