1.导入依赖
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.3'
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.0.3'
2.在布局中写入
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/refreshlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.scwang.smartrefresh.layout.header.ClassicsHeader
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.scwang.smartrefresh.layout.header.ClassicsHeader>
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
<com.scwang.smartrefresh.layout.footer.ClassicsFooter
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.scwang.smartrefresh.layout.footer.ClassicsFooter>
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
在里面包住listview或者recyclerview即可
他们的刷新监听 SmartRefreshLayout为最外层控件得findbyid出来
SmartRefreshLayout.setOnRefreshListener 是下拉刷新
SmartRefreshLayout.setOnLoadmoreListener 是上拉加载
停止加载
SmartRefreshLayout.finishRefresh();
SmartRefreshLayout.finishLoadmore();
当走了这步之后他会立马变成刷新成功,稍后会消失
已经没有数据可以返回了就会显示全部加载完成,就不会再上拉请求了
SmartRefreshLayout.
setLoadmoreFinished(true); 就可以了
这样直接使用就是默认原生的效果,如果你需要制定自己的刷新效果把布局里面的ClassicsHeader修改为你自己自定义的效果即可,也支持直接放一张动图或图片或文字,上拉加载一样