【Android-SwipeRefreshLayout控件】下拉刷新
Android自带API ,V4包下面的下拉刷新控件
android.support.v4.widget.SwipeRefreshLayout
SwipeRefreshLayout只能包含一个控件
布局例子:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
应用例子:
/**
* SwipeRefreshLayout控件学习
*/
public class RefreshActicity extends AppCompatActivity {
SwipeRefreshLayout swipeRefreshLayout;
ListView listView;
List<Product> list = new ArrayList<>();
ProductAdapter adapter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_refresh);
swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
listView = findViewById(R.id.listView);
//获取数据
initData();
//设置适配器
adapter = new ProductAdapter(this, list);
listView.setAdapter(adapter);
//设置下拉进度的背景颜色,默认是白色
swipeRefreshLayout.setProgressBackgroundColorSchemeResource(android.R.color.white);
//设置下拉进度的肢体颜色
swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, R.color.colorPrimary, R.color.colorPrimaryDark);
//下拉时触发下拉动画,动画完毕后回调这个方法
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
//开始刷新,设置当前为刷新状态(刷新状态会屏蔽掉下拉事件)
swipeRefreshLayout.setRefreshing(true);
//耗时操作,比如联网获取数据
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
list.clear();
initData();
adapter.notifyDataSetChanged();
//加载完数据,设置为不刷新状态,将下拉进度收起来
swipeRefreshLayout.setRefreshing(false);
}
}, 2000);
}
});
}
/**
* 生成10条List数据
*/
private void initData() {
for (int i = 1; i <= 10; i++) {
Random random = new Random();
Product product = new Product("100" + i, "testdata", random.nextInt(100));
list.add(product);
}
}
}
【Android-SwipeRefreshLayout控件】下拉刷新的更多相关文章
- android控件 下拉刷新pulltorefresh
外国人写的下拉刷新控件,我把他下载下来放在网盘,有时候訪问不了github 支持各种控件下拉刷新 ListView.ViewPager.WevView.ExpandableListView.GridV ...
- android SwipeRefreshLayout google官方下拉刷新控件
下拉刷新功能之前一直使用的是XlistView很方便我前面的博客有介绍 SwipeRefreshLayout是google官方推出的下拉刷新控件使用方法也比较简单 今天就来使用下SwipeRefres ...
- Android自己定义控件--下拉刷新的实现
我们在使用ListView的时候.非常多情况下须要用到下拉刷新的功能.为了了解下拉刷新的底层实现原理,我採用自己定义ListView控件的方式来实现效果. 实现的基本原理是:自己定义ListView, ...
- Android仿苹果版QQ下拉刷新实现(二) ——贝塞尔曲线开发"鼻涕"下拉粘连效果
前言 接着上一期Android仿苹果版QQ下拉刷新实现(一) ——打造简单平滑的通用下拉刷新控件 的博客开始,同样,在开始前我们先来看一下目标效果: 下面上一下本章需要实现的效果图: 大家看到这个效果 ...
- Atitit.ui控件---下拉菜单选择控件的实现select html
Atitit.ui控件---下拉菜单选择控件的实现select html 1. 调用& model的实现 1 2. -----select.jsp------ 1 1. 调用& m ...
- Android仿苹果版QQ下拉刷新实现(一) ——打造简单平滑的通用下拉刷新控件
前言: 忙完了结婚乐APP的开发,终于可以花一定的时间放在博客上了.好了,废话不多说,今天我们要带来的效果是苹果版本的QQ下拉刷新.首先看一下目标效果以及demo效果: 因为此效果实现的步骤 ...
- 自己封装的工具类,使用原生SwipeRefreshLayout+RecycleView实现下拉刷新和加载更多
实现SwipeRefreshLayout+RecycleView实现刷新 在你的xml文件里写上如下代码: <android.support.v4.widget.SwipeRefreshLayo ...
- Android如何定制一个下拉刷新,上滑加载更多的容器
前言 下拉刷新和上滑加载更多,是一种比较常用的列表数据交互方式. android提供了原生的下拉刷新容器 SwipeRefreshLayout,可惜样式不能定制. 于是打算自己实现一个专用的.但是下拉 ...
- Android实现RecyclerView的下拉刷新和上拉载入很多其它
需求 先上效果图, Material Design风格的下拉刷新和上拉载入很多其它. 源代码地址(欢迎star) https://github.com/studychen/SeeNewsV2 假设对于 ...
- Android—自定义控件实现ListView下拉刷新
这篇博客为大家介绍一个android常见的功能——ListView下拉刷新(参考自他人博客,网址忘记了,阅读他的代码自己理解注释的,希望能帮助到大家): 首先下拉未松手时候手机显示这样的界面: 下面的 ...
随机推荐
- oracle杀死正在执行的进程
1 查询目前正在执行的终端和进程, SELECT /*+ rule */ s.username,decode(l.type,'TM','TABLE LOCK','TX','ROW LOCK',NULL ...
- 图片压缩java工具类
package com.net.util; import java.awt.Image; import java.awt.image.BufferedImage; import java.io.Fil ...
- ubuntu下安装navicat
1.去官网下载 https://www.navicat.com/en/download/navicat-premium 2.命令行输入(解压命令) tar -zxvf xxxxx.tar.gz 3.移 ...
- Is It A Tree? POJ - 1308(并查集判树)
Problem Description A tree is a well-known data structure that is either empty (null, void, nothing) ...
- java web开发环境设置
Mapped Statements collection does not contain value for后面是什么类什么方法之类的问题: 除了"https://changbl.itey ...
- S03_CH02_AXI_DMA PL发送数据到PS
S03_CH02_AXI_DMA PL发送数据到PS 1.1概述 本课程的设计原理分析. 本课程循序渐进,承接<S03_CH01_AXI_DMA_LOOP 环路测试>这一课程,在DATA ...
- Asp.net core 学习笔记 Node Service
我们知道 npm 是很大的库,很多轮子可以用 所以 .net core 替我们封装了一个调用 nodejs 的 service 就叫 node service 我们只要在 server 安装 node ...
- 怎样在浏览器端增加一条Cookie
可以使用 document.cookie, 这个属性可读可写, 读时是读取所有没有设置HttpOnly的cookie作为一个字符串返回, 写时是将一个cookie写入到document.cookie中 ...
- X509证书在window server 2003/IIS 6环境部署
利用makecert.exe工具生成的X509证书在winform程序中运行正常,但是给部署在IIS中的应用程序用却获取不到证书信息,返回为空.原因是,iis没有权限读取位于证书存储区的X509证书, ...
- IEnumerable<T>和IQuryable<T>的区别
https://stackoverflow.com/questions/1578778/using-iqueryable-with-linq/1578809#1578809 The main diff ...