可变化加载样式的下拉刷新和上拉加载

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修改为你自己自定义的效果即可,也支持直接放一张动图或图片或文字,上拉加载一样

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值