android自带下拉刷新SwipeRefreshLayout
也是一个布局容器,只有一个子组件,类似scrollView
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/swipeLayout" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout> </android.support.v4.widget.SwipeRefreshLayout>
public class MainActivity extends AppCompatActivity {
SwipeRefreshLayout swipeRefreshLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipeLayout);
swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent,
R.color.colorPrimary,
R.color.colorPrimary,
R.color.colorPrimaryDark);
swipeRefreshLayout.setSize(SwipeRefreshLayout.DEFAULT);;
swipeRefreshLayout.setProgressViewOffset(true, 0, 200);
swipeRefreshLayout.setProgressViewEndTarget(true, 100);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
new Thread(new Runnable() {
@Override
public void run() {
try {
sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
mHandler.sendEmptyMessage(1);
}
}).start();
}
});}
//handler
@SuppressLint("HandlerLeak")
Handler mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 1:
Toast.makeText(MainActivity.this, "刷新成功", Toast.LENGTH_SHORT).show();
swipeRefreshLayout.setRefreshing(false);
break;
}
}
};
}
属性一运行便知道,在监听器里执行刷新任务,用handler通知主线程
android自带下拉刷新SwipeRefreshLayout的更多相关文章
- 安卓自带下拉刷新SwipeRefreshLayout加入上拉刷新功能
在项目里面要用到刷新库.曾经都是使用第三方的.只是看到官方出了 SwipeRefreshLayout之后就用SwipeRefreshLayout.可是不知道什么原因官方SwipeRefreshL ...
- 1、Android自己的下拉刷新SwipeRefreshLayout
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/ ...
- Android Material Design控件使用(四)——下拉刷新 SwipeRefreshLayout
使用下拉刷新SwipeRefreshLayout 说明 SwipeRefreshLayout是Android官方的一个下拉刷新控件,一般我们使用此布局和一个RecyclerView嵌套使用 使用 xm ...
- Android内置下拉刷新组件SwipeRefreshLayout
也许下拉刷新之前,你可能会使用一些第三方的开源库,例如PullToRefresh, ActionBar-PullToRefresh等待,但现在有的正式组成部分---SwipeRefreshLayout ...
- Android listview下拉刷新 SwipeRefreshLayout
今天在Google+上看到了SwipeRefreshLayout这个名词,遂搜索了下,发现竟然是刚刚google更新sdk新增加的一个widget,于是赶紧抢先体验学习下. SwipeRefreshL ...
- Android下拉刷新-SwipeRefreshLayout,RecyclerView完全解析之下拉刷新与上拉加载SwipeRefreshLayout)
SwipeRefrshLayout是Google官方更新的一个Widget,可以实现下拉刷新的效果.该控件集成自ViewGroup在support-v4兼容包下,不过我们需要升级supportlibr ...
- Android下拉刷新-SwipeRefreshLayout
现在市面上新闻类的App基本上都有下拉刷新,算是一个标配吧,网上关于下拉刷新的博客也有很多,实现方式可以使用开源的PullToRefresh,自定义ListView,或者可以直接使用LineLayOu ...
- Android原生下拉刷新SwipeRefreshLayout实践
本篇文章翻译自Ravi Tamada的Android Swipe Down to Refresh ListView Tutorial 首先来看一下效果图 你应该发现很多的android app比如Tw ...
- Android——谷歌官方下拉刷新控件SwipeRefreshLayout(转)
转自:http://blog.csdn.net/zouzhigang96/article/details/50476402 版权声明:本文为博主原创文章,未经博主允许不得转载. 前言: 如今谷歌推出了 ...
随机推荐
- 2.Strom-入门案例
- Windows10数字权利永久激活教程
很多人用Windows10系统,但是没有办法激活,这个教程一定会让你永久激活windows10系统(并非ksm) 打开设置,查看是否激活 如果激活的话,先退掉秘钥,在Windows power ...
- java中类的构造及其使用
class Person{ // 属性 public String name; public int age; // 构造方法 public Person(){ ...
- Oracle复习(复习精简版v1.0)
自己没记不住的,超基础Oracle知识,新手可以看一下. 大多数例子是用scott用户中的emp表完成 排序:order by 列名 desc是降序,默认是升序: update 表名 set 列 ...
- Typora操作总结
Typora 1. Markdown 是一种轻量级标记语言,它允许人们使用易读易写的纯文本格式编写文档 1.1 目录 [toc] 2. 结构类操作 2.1 多级标题 # 一级标题 ...
- leetcode1558题解【贪心】
leetcode1558.得到目标数组的最少函数调用次数 题目链接 算法 贪心 时间复杂度O(nlogN),N为数组中最大的那个数. 1.题意就是给定一个函数,该函数有两种功能,一种就是将数组中的所有 ...
- php 图片转base4的格式
<?php $url = '1.jpg'; $base64_img = base64_encode(file_get_contents($url));//将图片转base64编码 $imgArr ...
- ElasticSearch 简单的crud查询
//数据库和es的对应关系(学习文档可以参考https://es.xiaoleilu.com/010_Intro/35_Tutorial_Aggregations.html) //如下接口调用都是使用 ...
- Python面向对象基础变量
In [1]: class A: ...: NAME = 'A' # 类的直接下级作用域 叫做类变量 ...: def init(self, name): ...: self.name = name ...
- Candy (candy)
Description Due to its great contribution to the maintenance of world peace, Dzx was given an unlimi ...