今天看博客,发现有了这个下拉刷新的控件,效果看上去还蛮好的,于是我也想研究的是使用一下,写个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的使用的更多相关文章

  1. android官方下拉刷新控件SwipeRefreshLayout的使用

    可能开发安卓的人大多数都用过很多下拉刷新的开源组件,但是今天用了官方v4支持包的SwipeRefreshLayout觉得效果也蛮不错的,特拿出来分享. 简介:SwipeRefreshLayout组件只 ...

  2. Android——谷歌官方下拉刷新控件SwipeRefreshLayout(转)

    转自:http://blog.csdn.net/zouzhigang96/article/details/50476402 版权声明:本文为博主原创文章,未经博主允许不得转载. 前言: 如今谷歌推出了 ...

  3. 第一个开源控件:Google 官方下拉刷新控件 SwipeRefreshLayout 强化版,支持上拉刷新

    最近比较闲,所以趁着这时间撸了个SwipeRefreshLayout的加强版,Github地址. 原版只支持下拉刷新,强化之后支持上拉刷新和一进入页面就加载刷新,整个控件的加载动画是一致的,毫无违和感 ...

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

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

  5. Android之官方下拉刷新控件SwipeRefreshLayout

    SwipeRefreshLayout 是在V4包里面,首先要先导入V4包,最新的V4包里面才有这控件 首先是布局 <android.support.v4.widget.SwipeRefreshL ...

  6. Android SwipeRefreshLayout 官方下拉刷新控件介绍

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24521483 下面App基本都有下拉刷新的功能,以前基本都使用XListView ...

  7. android SwipeRefreshLayout google官方下拉刷新控件

    下拉刷新功能之前一直使用的是XlistView很方便我前面的博客有介绍 SwipeRefreshLayout是google官方推出的下拉刷新控件使用方法也比较简单 今天就来使用下SwipeRefres ...

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

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

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

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

随机推荐

  1. 12 stark组件之pop,按钮,url,页面

    1.Window open() 方法 http://www.runoob.com/jsref/met-win-open.html 效果图   2.admin的pop添加按钮 3.stark之pop功能 ...

  2. BZOJ2439【中山市选2011】序列

    题面 题解 设$f[i]$表示将$[1,i]$修改为递增的最小代价, $g[i]$表示将$[i,n]$修改为递减的最小代价. $L[i]$表示将$[1,i]$修改为倒$\text V$的代价 $$ \ ...

  3. [SDOI2018]战略游戏 圆方树,树链剖分

    [SDOI2018]战略游戏 这题是道路相遇(题解)的升级版,询问的两个点变成了\(S\)个点. LG传送门 还是先建出圆方树,考虑对于询问的\(S\)个点,答案就是圆方树上能包含这些点的最小连通块中 ...

  4. druid之监控设置及问题小记

    druid是什么注不再赘述了.想了解直接参见 https://github.com/alibaba/druid/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98 本文 ...

  5. Sqlite数据库sqlite3命令小记

    SQLite库包含一个名字叫做sqlite3的命令行,它可以让用户手工输入并执行面向SQLite数据库的SQL命令.本文档提供一个样使用sqlite3的简要说明. 开始 启动sqlite3程序,仅仅需 ...

  6. sqlmap简单中文说明

    首先下载需要的文件,如果是windows环境直接到http://sqlmap.org/下载安装所需要的文件即可. 更新 svn checkout https://svn.sqlmap.org/sqlm ...

  7. 电商打折套路分析 —— Python数据分析练习

    电商打折套路分析 ——2016天猫双十一美妆数据分析 数据简介 此次分析的数据来自于城市数据团对2016年双11天猫数据的采集和整理,原始数据为.xlsx格式 包括update_time/id/tit ...

  8. Unity优化方向——优化Unity游戏中的图形渲染(译)

    CPU bound:CPU性能边界,是指CPU计算时一直处于占用率很高的情况. GPU bound:GPU性能边界,同样的是指GPU计算时一直处于占用率很高的情况. 原文:https://unity3 ...

  9. 服务治理-> Spring Cloud Eureka

    服务治理->搭建服务注册中心 服务治理可以说是微服务架构中最为核心和基础的模块, 它主要用来实现各个微服务 实例的自动化注册与发现. 为什么我们在微服务架构中那么需要服务治理模块呢?微服务 系统 ...

  10. 深度学习中数据的augmentation

    为了提高模型的泛化能力,同时也为了增大数据集,我们往往需要对数据进行augmentation,在这篇博客中,将总结一下可以对数据进行的augmentation. 1.颜色数据增强,对图像亮度.饱和度. ...