android SwipeRefreshLayout google官方下拉刷新控件
2024-10-07 16:12:10
下拉刷新功能之前一直使用的是XlistView很方便我前面的博客有介绍
SwipeRefreshLayout是google官方推出的下拉刷新控件使用方法也比较简单
今天就来使用下SwipeRefreshLayout 以后再需要时可以参考.
首先在布局里面加入SwipeRefreshLayout 布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swiperefreshlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"> <ListView
android:id="@+id/tab_topical_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> </android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
Activity文件中的代码
mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swiperefreshlayout); mSwipeRefreshLayout.setColorSchemeResources(R.color.colorRed , R.color.colorGre , R.color.colorBlu);
mSwipeRefreshLayout.setProgressViewEndTarget(true , 150);
mSwipeRefreshLayout.setOnRefreshListener(this);
使用setColorSchemeResources设置下拉刷新的图标颜色可设置四种颜色.
setProgressViewEndTarget(true , 150)设置距离顶端的距离
setOnRefreshListener(this)设置监听
监听方法:
//滑动手势监听 , 加载数据
@Override
public void onRefresh() {
Toast.makeText(getActivity() , "loding..." , Toast.LENGTH_SHORT).show();
getDate();//获取数据
mSwipeRefreshLayout.setRefreshing(false);
}
搞定了上面两步就可以使用SwipeRefreshLayout这个控件了.
看下效果:
很简单吧.
最新文章
- SQL Server 索引和表体系结构(非聚集索引)
- js变量及其作用域
- C#将字节流加密解密
- C# 泛型简介
- 转载 ASP.NET常用的正则表达式
- 【转】C++ 类中的static,const,及引用类型的初始化
- 转:maven报错非法字符:\65279 错误
- python排序(冒泡, 快速)
- QT中.pro文件的写法
- CodeForces 712D Memory and Scores
- 【MYSQL】ubuntu13安装mysql(转)
- ASP.NET MVC5 中百度ueditor富文本编辑器的使用
- memcached usage
- linux入门--Linux系统的优缺点
- ubuntu16.04 在线安装docker ce
- 结对项目:ATM
- Python shelve 模块
- 1.2.2 Excel中手机号或身份证号批量加密星号
- forEach、map、filter、find、sort、some等易错点整理
- HDU 1712 ACboy needs your help(分组背包入门题)
热门文章
- 如何让django方法自动地定期执行
- XSS Payload知识备忘
- label与input间距的小问题
- [转]ORACLE 动态执行SQL语句
- [转]在ASP.NET开发中容易忽略的2个小问题 Cookie乱码存取异常 和 iframe弹框的login跳转
- Nodejs 请求转发代理
- Stanford机器学习笔记-3.Bayesian statistics and Regularization
- NOIP模拟赛 夕阳
- linux下安装安装pcre-8.32 configure: error: You need a C++ compiler for C++ support
- 安装ESXi5.5遇到Relocating modules and starting up the kernel的处理