1.首先导入依赖
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0'
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0'
2.布局文件
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/mSwipeLayout"
app:srlEnableScrollContentWhenLoaded="true"
app:srlEnableFooterFollowWhenLoadFinished="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.scwang.smartrefresh.layout.header.ClassicsHeader
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srlClassicsSpinnerStyle="Translate"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<com.scwang.smartrefresh.layout.footer.ClassicsFooter
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srlClassicsSpinnerStyle="Translate"/>
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
3.Activity界面代码
//首先在activity界面继承OnRefreshListener,OnLoadMoreListener
implements OnRefreshListener,OnLoadMoreListener
//mSwipeLayout.autoRefresh();//触发自动刷新
//上拉加载
@Override
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
refreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
refreshLayout.finishLoadMore();
}
},2000);
}
//下拉刷新
@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
refreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
refreshLayout.finishRefresh();
refreshLayout.resetNoMoreData();//setNoMoreData(false);
}
},2000);
}