Android下拉刷新SwipeRefreshLayout简单用法
之前一直都想用下拉刷新,感觉上是庞大的工程,所以搁置了。现在学习了一下其实真的超级简单。
看了《第一行代码》以及 https://www.jianshu.com/p/3c402a9e4b7d文章
看上去是真的简单。SwipeRefreshLayout下嵌套一个控件
1.布局代码
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/mswipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" > <WebView
android:id="@+id/mwebview"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</WebView>
</android.support.v4.widget.SwipeRefreshLayout>
混编的app,这里嵌套了一个webview
2.Activity代码
mSwipe = findViewById(R.id.mswipeRefreshLayout);
private void setSwipe() {
/*
* 设置下拉刷新球颜色
*/
mSwipe.setColorSchemeResources(R.color.swipeColor1,R.color.swipeColor2,R.color.swipeColor3,R.color.swipeColor4,R.color.swipeColor5);
/*
* 设置下拉刷新的监听
*/
mSwipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
//刷新需执行的操作
}
});
}
我们可以在res/values/colors.xml文件中设置我们想要的颜色
<color name="swipeColor1">#3F51B5</color>
<color name="swipeColor2">#000000</color>
......
加载完毕后需要关闭下拉刷新球
mSwipe.setRefreshing(false);

3.打开页面自动刷新
mSwipe.measure(0,0);
mSwipe.setRefreshing(true);
在onMeasure之前 单独使用setRefreshing(true)是没有效果的
还可以复写onWindowFocusChanged当页面获得焦点的时刷新
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
mSwipe.setRefreshing(true);
}
也可以放到ui线程消息循环中排队
mSwipe.post(new Runnable() {
@Override
public void run() {
mSwipe.setRefreshing(true);
}
});
在刷新结束后关闭刷新球
public void SwipeIsFinish(){
if (mSwipe.isRefreshing()) {
mSwipe.setRefreshing(false);
}
}
Android下拉刷新SwipeRefreshLayout简单用法的更多相关文章
- Android下拉刷新-SwipeRefreshLayout,RecyclerView完全解析之下拉刷新与上拉加载SwipeRefreshLayout)
SwipeRefrshLayout是Google官方更新的一个Widget,可以实现下拉刷新的效果.该控件集成自ViewGroup在support-v4兼容包下,不过我们需要升级supportlibr ...
- Android下拉刷新-SwipeRefreshLayout
现在市面上新闻类的App基本上都有下拉刷新,算是一个标配吧,网上关于下拉刷新的博客也有很多,实现方式可以使用开源的PullToRefresh,自定义ListView,或者可以直接使用LineLayOu ...
- Android Material Design控件使用(四)——下拉刷新 SwipeRefreshLayout
使用下拉刷新SwipeRefreshLayout 说明 SwipeRefreshLayout是Android官方的一个下拉刷新控件,一般我们使用此布局和一个RecyclerView嵌套使用 使用 xm ...
- Android 下拉刷新
以前旧版用的是开源的PullToRefresh第三方库,该库现在已经不再维护了: chrisbanes/Android-PullToRefreshhttps://github.com/chrisban ...
- Android 下拉刷新上拉载入 多种应用场景 超级大放送(上)
转载请标明原文地址:http://blog.csdn.net/yalinfendou/article/details/47707017 关于Android下拉刷新上拉载入,网上的Demo太多太多了,这 ...
- Android下拉刷新效果实现
本文主要包括以下内容 自定义实现pulltorefreshView 使用google官方SwipeRefreshLayout 下拉刷新大致原理 判断当前是否在最上面而且是向下滑的,如果是的话,则加载数 ...
- Android-PullToRefresh下拉刷新库基本用法
How:(使用) 转自:http://blog.csdn.net/hantangsongming/article/details/42490277 PullToRefresh是一套实现非常好的下拉刷新 ...
- 【原创】窥视懒人的秘密---android下拉刷新开启手势的新纪元
小飒的成长史原创作品:窥视懒人的秘密---android下拉刷新开启手势的新纪元转载请注明出处 **************************************************** ...
- Android listview下拉刷新 SwipeRefreshLayout
今天在Google+上看到了SwipeRefreshLayout这个名词,遂搜索了下,发现竟然是刚刚google更新sdk新增加的一个widget,于是赶紧抢先体验学习下. SwipeRefreshL ...
随机推荐
- Linux 下迁移 Nexus3
Nexus3 的迁移过程还是非常简单,复制整个目录到新服务器,启动即可. 备份 在原来服务器上将 nexus3 整体目录备份即可. $ tar -zcvf nexus3.tar.gz nexus3/ ...
- Mysql 错误 Connection is read-only 解决方式
环境Spring+Mybatis <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.s ...
- Linux-设备-磁盘
磁盘的每个扇区为512bytes.磁盘的第一个扇区记录了整块磁盘的重要信息,包含有主引导分区(MBR):可以安装引导加载程序的地方,有446bytes:分区表(partition table):记录整 ...
- C - Max Sum Plus Plus HDU - 1024
用二位数组dp[i][j]记录组数为i,前j个数字的最大子段和. 转移方程: dp[i][j],考虑第j个数,第j个数可以并到前面那一组,此时dp[i][j]=dp[i][j-1]+arr[j],第j ...
- A - Smith Numbers POJ
While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University,no ...
- SpringCloud-Ribbon负载均衡机制、手写轮询算法
Ribbon 内置的负载均衡规则 在 com.netflix.loadbalancer 包下有一个接口 IRule,它可以根据特定的算法从服务列表中选取一个要访问的服务,默认使用的是「轮询机制」 Ro ...
- react-i8n
1. 在项目中安装 npm install react-intl --save 2.兼容Safari各个版本需要安装intl npm install intl --save 3.编写语言包 1.)新建 ...
- Springboot:整合Mybaits和Druid【监控】(十一)
MyBatis默认提供了一个数据库连接池PooledDataSource,在此我们使用阿里提供的Druid数据库连接池 项目下载:https://files.cnblogs.com/files/app ...
- HTML+CSS教程(五)外联样式、组选择器、圆角边框、样式优先级、伪类、盒子模型、元素溢出
一.外联样式 通过link标签引入外部css文件夹中的xxx.css文件到head标签中 例: 二. 1.组选择器 选择器名称1,选择器名称2,选择器名称3,…{属性:属性值;属性;属性值} 例: & ...
- json:格式化数据
formatData = JSON.Stringfy(data, null, 2)