使用如下:

1.先下载android-support-v4.jar最新版本,之前的版本是没有SwipeRefreshLayout下拉刷新控件的,如果已经更新,此步骤可省略。

2.在xml文件中引用android.support.v4.widget.SwipeRefreshLayout控件,在里面可以放置任何一个控件,例如ListView,gridview等。

[html] view plaincopy

 
  1. <android.support.v4.widget.SwipeRefreshLayout
  2. android:id="@+id/swipe_refresh"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent" >
  5. <ListView
  6. android:id="@+id/listview"
  7. android:layout_width="match_parent"
  8. android:layout_height="match_parent" >
  9. </ListView>
  10. </android.support.v4.widget.SwipeRefreshLayout>

3.在java文件中使用。

  1. /**
  2. * 主页
  3. * @author w.w
  4. */
  5. public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener {
  6. /**
  7. * 给ListView添加下拉刷新
  8. */
  9. private SwipeRefreshLayout swipeLayout;
  10. /**
  11. * ListView
  12. */
  13. private ListView listView;
  14. /**
  15. * ListView适配器
  16. */
  17. private ListViewAdapter adapter;
  18. private List<ItemInfo> infoList;
  19. @Override
  20. protected void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. setContentView(R.layout.activity_main);
  23. swipeLayout = (SwipeRefreshLayout) this.findViewById(R.id.swipe_refresh);
  24. swipeLayout.setOnRefreshListener(this);
  25. // 顶部刷新的样式
  26. swipeLayout.setColorScheme(android.R.color.holo_red_light, android.R.color.holo_green_light,
  27. android.R.color.holo_blue_bright, android.R.color.holo_orange_light);
  28. infoList = new ArrayList<ItemInfo>();
  29. ItemInfo info = new ItemInfo();
  30. info.setName("coin");
  31. infoList.add(info);
  32. listView = (ListView) this.findViewById(R.id.listview);
  33. adapter = new ListViewAdapter(this, infoList);
  34. listView.setAdapter(adapter);
  35. }
  36. public void onRefresh() {
  37. new Handler().postDelayed(new Runnable() {
  38. public void run() {
  39. swipeLayout.setRefreshing(false);
  40. ItemInfo info = new ItemInfo();
  41. info.setName("coin-refresh");
  42. infoList.add(info);
  43. adapter.notifyDataSetChanged();
  44. }
  45. }, 500);
  46. }
  47. }
 

demo下载地址:http://download.csdn.net/detail/xue_wei_love/7135315

来源:http://blog.csdn.net/wwzqj/article/details/22790521

google推出的SwipeRefreshLayout下拉刷新用法的更多相关文章

  1. 【转】google推出的SwipeRefreshLayout下拉刷新用法

    SwipeRefreshLayout是Google在support v4 19.1版本的library更新的一个下拉刷新组件,实现刷新效果更方便. 使用如下: 1.先下载android-support ...

  2. Android零基础入门第72节:SwipeRefreshLayout下拉刷新

    在实际开发中,经常都会遇到下拉刷新.上拉加载更多的情形,这一期就一起来学习Android系统的SwipeRefreshLayout下拉刷新组件. 一.SwipeRefreshLayout简介 Swip ...

  3. Android之SwipeRefreshLayout下拉刷新组件

    SwipeRefreshLayout概述 SwipeRefrshLayout是Google官方更新的一个Widget,可以实现下拉刷新的效果.该控件集成自ViewGroup在support-v4兼容包 ...

  4. google官方提供的下拉刷新控件SwipeRefreshLayout

    摘自:http://www.stormzhang.com/android/2014/03/29/android-swiperefreshlayout/ SwipeRefreshLayout Swipe ...

  5. 谷歌官方SwipeRefreshLayout下拉刷新的用法。

    <Android SwipeRefreshLayout:谷歌官方SDK包中的下拉刷新> 下拉刷新在如今移动开发中应用如此广泛和普遍,以至于谷歌干脆在SDK中给予支持.在android-su ...

  6. Android SwipeRefreshLayout 下拉刷新——Hi_博客 Android App 开发笔记

    以前写下拉刷新 感觉好费劲,要判断ListView是否滚到顶部,还要加载头布局,还要控制 头布局的状态,等等一大堆.感觉麻烦死了.今天学习了SwipeRefreshLayout 的用法,来分享一下,有 ...

  7. SwipeRefreshLayout下拉刷新

    1.SwipeRefreshLayout是Google在support v4 19.1版本的library更新的一个下拉刷新组件,实现刷新效果更方便. 弊端:只有下拉 //设置刷新控件圈圈的颜色 sw ...

  8. SwipeRefreshLayout下拉刷新简单用例

    自己的下拉刷新组件 下拉刷新并自动添加数据 MainActivity package com.shaoxin.myswiperefreshlayout; import android.graphics ...

  9. Android --SwipeRefreshLayout 下拉刷新

    1.Layout <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/id_swipe_ly" an ...

随机推荐

  1. node 学习笔记 - fs 文件操作

    本文同步自我的个人博客:http://www.52cik.com/2015/12/03/learn-node-fs.html 最近看到群里不少大神都开始玩 node 了,我感觉跟他们步伐越来越大了, ...

  2. htpasswd 详解

    Apache htpasswd命令用法详解 htpasswd建立和更新存储用户名.密码的文本文件, 用于对HTTP用户的basic认证. # /usr/local/apache/bin/htpassw ...

  3. codevs1227 方格取数2 注意数组啊啊啊啊啊啊啊啊啊啊

    一开始T了一组RE了一组,实在找不出错来,就把数组加了一个0竟然就多A了一组.很惊讶的又加了几个0最后竟然全A了!!! 懒得做了,改的是之前的那个蚯蚓的游戏问题.还是需要拆点,至于为什么不能重复走结点 ...

  4. 进化策略-python实现

    ESIndividual.py import numpy as np import ObjFunction class ESIndividual: ''' individual of evolutio ...

  5. hdu 3068 最长回文子串 TLE

    后缀数组+RMQ是O(nlogn)的,会TLE..... 标准解法好像是马拉车,O(n).... #include "algorithm" #include "cstdi ...

  6. Memory Allocation API In Linux Kernel && Linux Userspace、kmalloc vmalloc Difference、Kernel Large Section Memory Allocation

    目录 . 内核态(ring0)内存申请和用户态(ring3)内存申请 . 内核态(ring0)内存申请:kmalloc/kfree.vmalloc/vfree . 用户态(ring3)内存申请:mal ...

  7. Recon-Erlang线上系统诊断工具

    Erlang系统素以稳定可靠闻名,但是它也是c实现的,也是要管理比如内存,锁等等复杂的事情,也会出现Crash,而且crash的时候大部分原因是因为内存问题.为此erlang运行期提供了强大的自省机制 ...

  8. Pseudo-elements ::before, ::after 範例

    xhtml <strong class="amount">700</strong> css .amount::before {content:"$ ...

  9. easyui之datagrid的使用

    http://www.cnblogs.com/ruanmou001/p/3840954.html 一.神马是easyui jQuery EasyUI是一组基于jQuery的UI插件集合,而jQuery ...

  10. Struts2 自定义Result

    注意:我只要是解决自定义返回Json 和异常处理问题 新建一个类 AjaxResult   继承 StrutsResultSupport 看看代码吧 public class AjaxResult e ...