官方下拉刷新控件SwipeRefreshLayout的使用
今天看博客,发现有了这个下拉刷新的控件,效果看上去还蛮好的,于是我也想研究的是使用一下,写个demo。其实使用很简单的,但就是为了能使用这个新组建我下了好久的更新,后来还是直接去官网下载最新的ADT得到解决。
该控件的完整名字是android.support.v4.widget.SwipeRefreshLayout
因此在XML文件里,必须使用这个完整的名字,另外这个类似于linearlayout,是作为整个xml文件里的根节点用的。
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/srl"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test.MainActivity$PlaceholderFragment" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_test"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="aaaaaaaaaaa"/>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
然后在java代码里,只需要获取到这个控件,给这个控件设置一个onRefreshListener即可。
public static class PlaceholderFragment extends Fragment implements OnRefreshListener {
private SwipeRefreshLayout srl = null;
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
srl = (SwipeRefreshLayout) rootView.findViewById(R.id.srl);
srl.setOnRefreshListener(this);
srl.setColorScheme(android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_red_light,
android.R.color.holo_orange_light);
return rootView;
}
@Override
public void onRefresh() {
Toast.makeText(getActivity(), "onRefresh", Toast.LENGTH_SHORT).show();
new Thread(){
@Override
public void run() {
try {
sleep(3000);
srl.setRefreshing(false);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
}
}
最终就可以实现一个不错的下拉刷新的效果,非常的不错,终于不用为写出一个下拉刷新控件而发愁了……
官方下拉刷新控件SwipeRefreshLayout的使用的更多相关文章
- android官方下拉刷新控件SwipeRefreshLayout的使用
可能开发安卓的人大多数都用过很多下拉刷新的开源组件,但是今天用了官方v4支持包的SwipeRefreshLayout觉得效果也蛮不错的,特拿出来分享. 简介:SwipeRefreshLayout组件只 ...
- Android——谷歌官方下拉刷新控件SwipeRefreshLayout(转)
转自:http://blog.csdn.net/zouzhigang96/article/details/50476402 版权声明:本文为博主原创文章,未经博主允许不得转载. 前言: 如今谷歌推出了 ...
- 第一个开源控件:Google 官方下拉刷新控件 SwipeRefreshLayout 强化版,支持上拉刷新
最近比较闲,所以趁着这时间撸了个SwipeRefreshLayout的加强版,Github地址. 原版只支持下拉刷新,强化之后支持上拉刷新和一进入页面就加载刷新,整个控件的加载动画是一致的,毫无违和感 ...
- 【转】Android官方下拉刷新控件 SwipeRefreshLayout
今天在Google+上看到了SwipeRefreshLayout这个名词,遂搜索了下,发现竟然是刚刚google更新sdk新增加的一个widget,于是赶紧抢先体验学习下. SwipeRefreshL ...
- Android之官方下拉刷新控件SwipeRefreshLayout
SwipeRefreshLayout 是在V4包里面,首先要先导入V4包,最新的V4包里面才有这控件 首先是布局 <android.support.v4.widget.SwipeRefreshL ...
- Android SwipeRefreshLayout 官方下拉刷新控件介绍
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24521483 下面App基本都有下拉刷新的功能,以前基本都使用XListView ...
- android SwipeRefreshLayout google官方下拉刷新控件
下拉刷新功能之前一直使用的是XlistView很方便我前面的博客有介绍 SwipeRefreshLayout是google官方推出的下拉刷新控件使用方法也比较简单 今天就来使用下SwipeRefres ...
- Google SwipeRefreshLayout(Goolge官方下拉刷新控件)尝鲜
前天Google官方终于出了Android刷新控件——SwipeRefreshLayout. 使用前先需要将android.support.v4.jar升级到19.1.升级后,可能会出现SDK版本与A ...
- google官方提供的下拉刷新控件SwipeRefreshLayout
摘自:http://www.stormzhang.com/android/2014/03/29/android-swiperefreshlayout/ SwipeRefreshLayout Swipe ...
随机推荐
- 2597: [Wc2007]剪刀石头布
2597: [Wc2007]剪刀石头布 链接 分析: 费用流. 首先转化一下问题,整张图最优的情况是存在$C_n^3$个,即任意3个都行,然后考虑去掉最少不满足的三元环. 如果u赢了v,u向v连一条边 ...
- P3877 [TJOI2010]打扫房间
xswl以为是个插头dp,然后发现就是个sb题 相当于就是个匹配.每个格子度数为2,所以可以匹配2个相邻的点.匹配显然的用网络流.最后check有没有不匹配的点即可. #include<bits ...
- 从《乱世王者》看腾讯SLG手游如何搭建完整安全服务
WeTest 导读 <乱世王者>是由腾讯旗下天美工作室群自主研发的一款战争策略手游,在经历了2015年-2017年的SLG品类手游的爆发之势下,于2017年11月21日正式公测. < ...
- 开源第三方登录组件OAuthLogin2.0 架构解析及开源地址
OAuthLogin2.0介绍地址: 入门地址:http://www.cnblogs.com/dazhuangtage/p/6306133.html Nuget地址:https://www.nuget ...
- VB.NET 仿Edge风格的TabControl控件
原本是想写个Chrome内核的浏览器,但是.net语言下比较好用类库的并不多,尝试过CefSharp.Xilium.CefGlue,都发现很多坑,所以这个项目就烂尾了,现在将还有点用的代码发出来给大家 ...
- spring-boot2.x Application properties属性配置
# =================================================================== # COMMON SPRING BOOT PROPERTIE ...
- jquery 3.0 新版本
https://code.jquery.com/
- Windows下LimeSDR Mini使用说明
本文内容.开发板及配件仅限用于学校或科研院所开展科研实验! 淘宝店铺名称:开源SDR实验室 LimeSDR链接:https://item.taobao.com/item.htm?spm=a230r.1 ...
- 从零系列--node爬虫利用进程池写数据
1.主进程 const http = require('http'); const fs = require('fs'); const cheerio = require('cheerio'); co ...
- UVA 816 Abbott's Revenge 紫书
紫书的这道题, 作者说是很重要. 但看着题解好长, 加上那段时间有别的事, 磨了几天没有动手. 最后,这道题我打了五遍以上 ,有两次被BUG卡了,找了很久才找到. 思路紫书上有,就缺少输入和边界判断两 ...