这篇文章给大家介绍Android项目中使用SwipeRefreshLayout组件实现一个下拉刷新功能,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。SwipeRefreshLayout概述SwipeRefrshLayo
这篇文章给大家介绍Android项目中使用SwipeRefreshLayout组件实现一个下拉刷新功能,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
SwipeRefreshLayout概述
SwipeRefrshLayout是Google官方更新的一个Widget,可以实现下拉刷新的效果。该控件集成自ViewGroup在support-v4兼容包下,不过我们需要升级supportlibrary的版本到19.1以上。
用户通过手势或者点击某个按钮实现内容视图的刷新,布局里加入SwipeRefreshLayout嵌套一个子视图如ListView、 RecyclerView等,触发刷新会通过OnRefreshListener的onRefresh方法回调,我们在这里执行页面数据的刷新,每次手势 的完成都会执行一次通知,根据滑动距离判断是否需要回调。setRefreshing(false)通过代码直接取消刷新,true则手动设置刷新调出刷 新视图。setEnabled(false)通过boolean控制是否禁用手势刷新 。
基本使用的方法如下:
setOnRefreshListener(OnRefreshListener):添加下拉刷新监听器
setRefreshing(boolean):显示或者隐藏刷新进度条
isRefreshing():检查是否处于刷新状态
使用非常简单,用一个简单案例来介绍SwipeRefreshLayout下拉刷新的功能。
布局文件
<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.SwipeRefreshLayout xmlns:android="Http://schemas.android.com/apk/res/android" android:id="@+id/v7_refresh" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/back"> <android.support.v7.widget.RecyclerView android:id="@+id/v7_recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" /></android.support.v4.widget.SwipeRefreshLayout>
--结束END--
本文标题: Android项目中使用SwipeRefreshLayout组件实现一个下拉刷新功能
本文链接: https://www.lsjlt.com/news/225446.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0