核心代码如下:
for(int i=1;i<5;i++){ LinearLayoutManager layoutManager= new LinearLayoutManager(getContext()); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); IRecyclerView recyclerView = new IRecyclerView(getContext()); recyclerView.setRefreshEnabled(true); recyclerView.setRefreshHeaderView(new ClassicRefreshHeaderView(getContext())); recyclerView.setLoadMoreFooterView(R.layout.layout_irecyclerview_load_more_footer); recyclerView.setLoadMoreEnabled(true); // recyclerView.addHeaderView(headView); recyclerView.setLayoutManager(layoutManager); recyclerView.setOnLoadMoreListener(this); recyclerView.setOnRefreshListener(this); PolymerizationOtherAdapter mPolymerizationOtherAdapter = new PolymerizationOtherAdapter(getContext()); recyclerView.setIAdapter(mPolymerizationOtherAdapter); mPolymerizationOtherAdapter.setOnRecyclerItemClickListener(new RecyclerItemClickListener(){ @Override public void onItemClickListener(int position) { } }); mViewList.add(recyclerView);
refresh headview
package com.d1ev.touch.App.view.header; import android.content.Context; import android.util.AttributeSet; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; import com.aspsine.irecyclerview.RefreshTrigger; import com.d1ev.touch.App.R; /** * Created by apple on 2016/12/11. */ public class ClassicRefreshHeaderView extends RelativeLayout implements RefreshTrigger { private ImageView ivArrow; private ImageView ivSuccess; private TextView tvRefresh; private ProgressBar progressBar; private Animation rotateUp; private Animation rotateDown; private boolean rotated = false; private int mHeight; public ClassicRefreshHeaderView(Context context) { this(context, null); } public ClassicRefreshHeaderView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public ClassicRefreshHeaderView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); inflate(context, R.layout.layout_irecyclerview_classic_refresh_header_view, this); tvRefresh = (TextView) findViewById(R.id.tvRefresh); ivArrow = (ImageView) findViewById(R.id.ivArrow); ivSuccess = (ImageView) findViewById(R.id.ivSuccess); progressBar = (ProgressBar) findViewById(R.id.progressbar); rotateUp = AnimationUtils.loadAnimation(context, R.anim.rotate_up); rotateDown = AnimationUtils.loadAnimation(context, R.anim.rotate_down); } @Override public void onStart(boolean automatic, int headerHeight, int finalHeight) { this.mHeight = headerHeight; progressBar.setIndeterminate(false); } @Override public void onMove(boolean isComplete, boolean automatic, int moved) { if (!isComplete) { ivArrow.setVisibility(VISIBLE); progressBar.setVisibility(GONE); ivSuccess.setVisibility(GONE); if (moved <= mHeight) { if (rotated) { ivArrow.clearAnimation(); ivArrow.startAnimation(rotateDown); rotated = false; } tvRefresh.setText("SWIPE TO REFRESH"); } else { tvRefresh.setText("RELEASE TO REFRESH"); if (!rotated) { ivArrow.clearAnimation(); ivArrow.startAnimation(rotateUp); rotated = true; } } } } @Override public void onRefresh() { ivSuccess.setVisibility(GONE); ivArrow.clearAnimation(); ivArrow.setVisibility(GONE); progressBar.setVisibility(VISIBLE); tvRefresh.setText("REFRESHING"); } @Override public void onRelease() { } @Override public void onComplete() { rotated = false; ivSuccess.setVisibility(VISIBLE); ivArrow.clearAnimation(); ivArrow.setVisibility(GONE); progressBar.setVisibility(GONE); tvRefresh.setText("COMPLETE"); } @Override public void onReset() { rotated = false; ivSuccess.setVisibility(GONE); ivArrow.clearAnimation(); ivArrow.setVisibility(GONE); progressBar.setVisibility(GONE); } }refreshtrigger interfac
public interface RefreshTrigger { void onStart(boolean var1, int var2, int var3); void onMove(boolean var1, boolean var2, int var3); void onRefresh(); void onRelease(); void onComplete(); void onReset(); }footer view:
public class LoadMoreFooterView extends FrameLayout { private Status mStatus; private View mLoadingView; private View mErrorView; private View mTheEndView; private OnRetryListener mOnRetryListener; public LoadMoreFooterView(Context context) { this(context, null); } public LoadMoreFooterView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public LoadMoreFooterView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); LayoutInflater.from(context).inflate(R.layout.layout_irecyclerview_load_more_footer_view, this, true); mLoadingView = findViewById(R.id.loadingView); mErrorView = findViewById(R.id.errorView); mTheEndView = findViewById(R.id.theEndView); mErrorView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mOnRetryListener != null) { mOnRetryListener.onRetry(LoadMoreFooterView.this); } } }); setStatus(Status.GONE); } public void setOnRetryListener(OnRetryListener listener) { this.mOnRetryListener = listener; } public Status getStatus() { return mStatus; } public void setStatus(Status status) { this.mStatus = status; change(); } public boolean canLoadMore() { return mStatus == Status.GONE || mStatus == Status.ERROR; } private void change() { switch (mStatus) { case GONE: mLoadingView.setVisibility(GONE); mErrorView.setVisibility(GONE); mTheEndView.setVisibility(GONE); break; case LOADING: mLoadingView.setVisibility(VISIBLE); mErrorView.setVisibility(GONE); mTheEndView.setVisibility(GONE); break; case ERROR: mLoadingView.setVisibility(GONE); mErrorView.setVisibility(VISIBLE); mTheEndView.setVisibility(GONE); break; case THE_END: mLoadingView.setVisibility(GONE); mErrorView.setVisibility(GONE); mTheEndView.setVisibility(VISIBLE); break; } } public enum Status { GONE, LOADING, ERROR, THE_END } public interface OnRetryListener { void onRetry(LoadMoreFooterView view); } }