短视频平台开发,下拉刷新、到底自动刷新新内容
短视频平台开发,下拉刷新、到底自动刷新新内容实现的相关代码
第一步:
添加依赖
1 | <br>implementation 'com.scwang.smart:refresh-layout-kernel:2.0.3' <br>implementation 'com.scwang.smart:refresh-header-classics:2.0.3' <br>implementation 'com.scwang.smart:refresh-footer-classics:2.0.3' |
第二步:
添加布局文件
1 | <br><RelativeLayout xmlns:android= "http://schemas.android.com/apk/res/android" <br> xmlns:tools= "http://schemas.android.com/tools" <br> android:layout_width= "match_parent" <br> android:layout_height= "match_parent" <br> tools:context= ".ui.life.LifeFragment" <br> android:background= "#F1F1f1" <br> ><br> <com.scwang.smart.refresh.layout.SmartRefreshLayout<br> xmlns:android= "http://schemas.android.com/apk/res/android" <br> android:id= "@+id/refreshLayout" <br> android:layout_width= "match_parent" <br> android:layout_height= "match_parent" ><br> <com.scwang.smart.refresh.header.ClassicsHeader<br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" /><br> <androidx.recyclerview.widget.RecyclerView<br> android:layout_width= "match_parent" <br> android:layout_height= "match_parent" <br> android:id= "@+id/life_recycler" <br> /><br> <com.scwang.smart.refresh.footer.ClassicsFooter<br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" /><br> </com.scwang.smart.refresh.layout.SmartRefreshLayout><br></RelativeLayout> |
第三步:
初始化代码
1 | <br>mRefresh.setRefreshHeader( new ClassicsHeader(getContext()));<br>mRefresh.setRefreshFooter( new ClassicsFooter(getContext()));<br>mRefresh.setOnRefreshListener( new OnRefreshListener() {<br> @Override<br> public void onRefresh(RefreshLayout refreshlayout) {<br> refreshlayout.finishRefresh(2000 /*,false*/ ); //传入false表示刷新失败<br> }<br>});<br>mRefresh.setOnLoadMoreListener(new OnLoadMoreListener() {<br> @Override<br> public void onLoadMore(RefreshLayout refreshlayout) {<br> refreshlayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败<br> }<br>}); |
以上就是短视频平台开发,下拉刷新、到底自动刷新新内容实现的相关代码, 更多内容欢迎关注之后的文章
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现