短视频平台开发,下拉刷新、到底自动刷新新内容
短视频平台开发,下拉刷新、到底自动刷新新内容实现的相关代码
第一步:
添加依赖
implementation 'com.scwang.smart:refresh-layout-kernel:2.0.3'
implementation 'com.scwang.smart:refresh-header-classics:2.0.3'
implementation 'com.scwang.smart:refresh-footer-classics:2.0.3'
第二步:
添加布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.life.LifeFragment"
android:background="#F1F1f1"
>
<com.scwang.smart.refresh.layout.SmartRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.scwang.smart.refresh.header.ClassicsHeader
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/life_recycler"
/>
<com.scwang.smart.refresh.footer.ClassicsFooter
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
</RelativeLayout>
第三步:
初始化代码
mRefresh.setRefreshHeader(new ClassicsHeader(getContext()));
mRefresh.setRefreshFooter(new ClassicsFooter(getContext()));
mRefresh.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(RefreshLayout refreshlayout) {
refreshlayout.finishRefresh(2000/*,false*/);//传入false表示刷新失败
}
});
mRefresh.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void onLoadMore(RefreshLayout refreshlayout) {
refreshlayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败
}
});
以上就是短视频平台开发,下拉刷新、到底自动刷新新内容实现的相关代码, 更多内容欢迎关注之后的文章