首先须把你的support library的版本升级到19.1或更新

效果:

使用超级简单!

在layout中添加SwipeRefreshLayout

 <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent" > <ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" > <TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="10dp"
android:text="@string/swipe_to_refresh"
android:textSize="20sp"
android:textStyle="bold" />
</ScrollView> </android.support.v4.widget.SwipeRefreshLayout>

在Activity中使用:

 tv = (TextView)findViewById(R.id.textView1);
swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipe_container);
//设置刷新时动画的颜色,可以设置4个
swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light);
swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override
public void onRefresh() {
tv.setText("正在刷新");
// TODO Auto-generated method stub
new Handler().postDelayed(new Runnable() { @Override
public void run() {
// TODO Auto-generated method stub
tv.setText("刷新完成");
swipeRefreshLayout.setRefreshing(false);
}
}, );
}
});

PS:setColorScheme()已经弃用,使用setColorSchemeResources()来设置颜色。

SwipeRefreshLayout嵌套ScrollView实现下拉刷新的更多相关文章

  1. [RN] React Native 使用 FlatList 和 ScrollView 的下拉刷新问题

    React Native 使用 FlatList 和 ScrollView 实现 下拉刷新时,RefreshControl 控件不起作用, 后来经查明,原来 RefreshControl 要加在 Sc ...

  2. Google SwipeRefreshLayout(Goolge官方下拉刷新控件)尝鲜

    前天Google官方终于出了Android刷新控件——SwipeRefreshLayout. 使用前先需要将android.support.v4.jar升级到19.1.升级后,可能会出现SDK版本与A ...

  3. SwipeRefreshLayout的使用,下拉刷新

    1. <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android ...

  4. Google自己的下拉刷新组件SwipeRefreshLayout

    SwipeRefreshLayout SwipeRefreshLayout字面意思就是下拉刷新的布局,继承自ViewGroup,在support v4兼容包下,但必须把你的support librar ...

  5. Android listview下拉刷新 SwipeRefreshLayout

    今天在Google+上看到了SwipeRefreshLayout这个名词,遂搜索了下,发现竟然是刚刚google更新sdk新增加的一个widget,于是赶紧抢先体验学习下. SwipeRefreshL ...

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

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

  7. 【转】Android官方下拉刷新控件 SwipeRefreshLayout

    今天在Google+上看到了SwipeRefreshLayout这个名词,遂搜索了下,发现竟然是刚刚google更新sdk新增加的一个widget,于是赶紧抢先体验学习下. SwipeRefreshL ...

  8. Android Material Design控件使用(四)——下拉刷新 SwipeRefreshLayout

    使用下拉刷新SwipeRefreshLayout 说明 SwipeRefreshLayout是Android官方的一个下拉刷新控件,一般我们使用此布局和一个RecyclerView嵌套使用 使用 xm ...

  9. Google官方下拉刷新组件---SwipeRefreshLayout

    今天在Google+上看到了SwipeRefreshLayout这个名词,遂搜索了下,发现竟然是刚刚google更新sdk新增加的一个widget,于是赶紧抢先体验学习下. SwipeRefreshL ...

随机推荐

  1. Linux执行.sh文件,提示No such file or directory的问题的解决方法

    亲测有效:http://www.jb51.net/LINUXjishu/56395.html Linux执行.sh文件,提示No such file or directory的问题的解决方法 在win ...

  2. Quartz.NET在ASP.NET 中使用

    Quartz.NET 项目地址 http://quartznet.sourceforge.net/ common logging是一个通用日志接口,log4net是一个具体实现 ,也可以使用NLog, ...

  3. Apache本地配置虚拟域名

    转载+修改 例:虚拟域名为 aaa.com 端口为默认80 index.html所在目录  D:/wamp/www/web 不用解析域名,使用虚假的域名也可以 apache安装完默认是不开启虚拟服务器 ...

  4. php使用 utf8_encode 来将特殊字符转成 utf8

    如果在接受 $_POST 或 $_GET 时发生类似的错误报告:SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xF6te ...

  5. ASP.NET MVC HtmlHelper 类的扩展方法

    再ASP.NET MVC编程中用到了R语法,在View页面编辑HTML标签的时候,ASP.NET MVC 为我们准备好了可以辅助我们写这些标签的办法,它们就是HtmlHelper.微软官方地址是:ht ...

  6. nginx把两个不同的网站挂到同一台服务器的80端口上

    本文主要分享如果利用nginx把两个不同的网站挂到同一台服务器的80端口上 最终效果 例如:www.manyjar.com (web服务器是8080端口)和ishenghuo.manyjar.com ...

  7. 微信小程序——豆瓣电影——(1):基础入门

    准备 Demo 项目地址 https://github.com/zce/weapp-demo Clone or Download(需准备GIT环境) $ cd path/to/project/root ...

  8. java设计模式(详)

    http://www.runoob.com/design-pattern/design-pattern-tutorial.html

  9. mongodb副本集数据同步的踩坑

    一.故事 最近随着搞活动比较频繁导致数据库出现了波动,后端日志总是报数据库连接和读取的问题.由于我设置的是读写分离(伪的,通过设置副本集的读取策略实现的,设置的db.getMongo().setRea ...

  10. elasticSearch6源码分析(10)SettingsModule

    1.SettingsModule概述 /** * A module that binds the provided settings to the {@link Settings} interface ...