下拉刷新功能之前一直使用的是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这个控件了.

看下效果:

很简单吧.

最新文章

  1. SQL Server 索引和表体系结构(非聚集索引)
  2. js变量及其作用域
  3. C#将字节流加密解密
  4. C# 泛型简介
  5. 转载 ASP.NET常用的正则表达式
  6. 【转】C++ 类中的static,const,及引用类型的初始化
  7. 转:maven报错非法字符:\65279 错误
  8. python排序(冒泡, 快速)
  9. QT中.pro文件的写法
  10. CodeForces 712D Memory and Scores
  11. 【MYSQL】ubuntu13安装mysql(转)
  12. ASP.NET MVC5 中百度ueditor富文本编辑器的使用
  13. memcached usage
  14. linux入门--Linux系统的优缺点
  15. ubuntu16.04 在线安装docker ce
  16. 结对项目:ATM
  17. Python shelve 模块
  18. 1.2.2 Excel中手机号或身份证号批量加密星号
  19. forEach、map、filter、find、sort、some等易错点整理
  20. HDU 1712 ACboy needs your help(分组背包入门题)

热门文章

  1. 如何让django方法自动地定期执行
  2. XSS Payload知识备忘
  3. label与input间距的小问题
  4. [转]ORACLE 动态执行SQL语句
  5. [转]在ASP.NET开发中容易忽略的2个小问题 Cookie乱码存取异常 和 iframe弹框的login跳转
  6. Nodejs 请求转发代理
  7. Stanford机器学习笔记-3.Bayesian statistics and Regularization
  8. NOIP模拟赛 夕阳
  9. linux下安装安装pcre-8.32 configure: error: You need a C++ compiler for C++ support
  10. 安装ESXi5.5遇到Relocating modules and starting up the kernel的处理