ListView(2)最简单的上拉刷新,下拉刷新
效果
最简单的上拉刷新和下拉刷新,当listview滚动到底部时向上拉刷新数据。当listview滚动到最顶部时下拉刷新。
图1,上拉刷新 图2,下拉刷新
1.设置lisview
加载header refresh,footer refresh,同时可选择关闭滚动到底部,顶部的动画。
listview = (ListView) tbhost.findViewById(R.id.tab_weixin_list);
adapter = new TabWeixinListAdapter(context,listview); headerRefresh = tabHost.findViewById(R.id.ViewStub_header_refresh);
footerRefresh = tabHost.findViewById(R.id.ViewStub_footer_refresh); listview.setAdapter(adapter); if(android.os.Build.VERSION.SDK_INT >=){//关闭滚动到顶部,底部动画。
listview.setOverScrollMode(View.OVER_SCROLL_NEVER);
}
listview.setOnTouchListener(touchListener);
2.在onTouchEvent中处理事件
float startY;
View.OnTouchListener touchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
startY = event.getY();;
break;
case MotionEvent.ACTION_MOVE:
float y = event.getY();
if (y - startY < ){//上拉
if (!listview.canScrollVertically()){
footerRefresh.setVisibility(View.VISIBLE);
}
}else{//下拉
View cld = listview.getChildAt();
int bottom = cld.getBottom();
int het = cld.getHeight();
if (listview.getFirstVisiblePosition() == && bottom >= het ){
headerRefresh.setVisibility(View.VISIBLE);
}
}
break;
case MotionEvent.ACTION_UP:
headerRefresh.setVisibility(View.GONE);
footerRefresh.setVisibility(View.GONE);
if (listview.getFirstVisiblePosition() == || !listview.canScrollVertically()){
addSomeTableWeixinItem();
}
break;
default:
System.out.println("default ");
break;
}
return false;
}
};
listview.canScrollVertically() 这个函数可以用来判断当前view还可以向上拉多少,如果向上拉0都不可以,就说明在view底部。此函数对下拉不好用。
当 listview.getFirstVisiblePosition() == 0 时 listview滚动到了顶部。
3.footer_refresh_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/footer_fresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#D1D1D1"
android:gravity="center_horizontal"
android:orientation="horizontal" > <ProgressBar
android:id="@+id/footer_refresh_prgs"
style="@style/CustomProgressStyle"
android:layout_width="wrap_content"
android:indeterminateDuration="700"
android:layout_height="match_parent" /> <TextView
android:id="@+id/footer_refresh_txt"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:gravity="center_vertical"
android:text="刷新"
android:textSize="20sp" /> </LinearLayout>
4.header_refresh_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/footer_fresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:background="#D1D1D1"
android:orientation="horizontal" > <ProgressBar
android:id="@+id/header_refresh_prgs"
style="@style/CustomProgressStyle"
android:layout_width="wrap_content"
android:indeterminateDuration="700"
android:layout_height="match_parent" /> <TextView
android:id="@+id/header_refresh_txt"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:gravity="center_vertical"
android:text="刷新"
android:textSize="20sp" /> </LinearLayout>
5.listview的layout
<?xml version="1.0" encoding="utf-8"?>
<!-- <merge xmlns:android="http://schemas.android.com/apk/res/android" > --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab_weixin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <ViewStub
android:id="@+id/ViewStub_header_refresh"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#BFBFBF"
android:inflatedId="@+id/tab_weixin_refresh"
android:layout="@layout/header_refresh_layout" > </ViewStub> <TextView android:id="@+id/footer_fresh_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#BFBFBF"
android:gravity="center_horizontal|center_vertical"
android:textSize="20sp"
android:text="@string/find_qq_friends" /> <!-- android:overScrollMode=”never” -->
<ListView
android:id="@+id/tab_weixin_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</ListView> <ViewStub
android:id="@+id/ViewStub_footer_refresh"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#BFBFBF"
android:inflatedId="@+id/tab_weixin_footer_refresh"
android:layout="@layout/footer_refresh_layout" /> </LinearLayout> <!-- </merge> -->
ListView(2)最简单的上拉刷新,下拉刷新的更多相关文章
- Flutter学习笔记(25)--ListView实现上拉刷新下拉加载
如需转载,请注明出处:Flutter学习笔记(25)--ListView实现上拉刷新下拉加载 前面我们有写过ListView的使用:Flutter学习笔记(12)--列表组件,当列表的数据非常多时,需 ...
- ListView装上拉电阻下拉刷新
主要用到了这个几个文件.MainActivity是界面的Activity,MyAdapter是ListView的自己定义适配,MyListView是自己定义带头部LIistView,假设仅仅须要上拉载 ...
- Android之 RecyclerView,CardView 详解和相对应的上拉刷新下拉加载
随着 Google 推出了全新的设计语言 Material Design,还迎来了新的 Android 支持库 v7,其中就包含了 Material Design 设计语言中关于 Card 卡片概念的 ...
- 使用iScroll实现上拉或者下拉刷新
上拉或者下拉刷新的需求在移动端是非常常见的需求,大部分情况下,实现这个效果都使用网上现有的解决方案,例如有人使用swiper这个插件, 也有人使用iScroll这个滚动插件.本文的示例是利用iscro ...
- html5+css3实现上拉和下拉刷新
<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...
- jQuery模拟原生态App上拉刷新下拉加载
jQuery模拟原生态App上拉刷新下拉加载效果代码,鼠标上拉时会显示loading字样,并且会模拟加载一条静态数据,支持触屏设备使用. <!doctype html> <html ...
- ios 上拉载入下拉刷新Dome
为练手写了一个小的上拉载入很多其它下拉刷新的小的Dome . 没有太多的技术含量,仅仅是作为新手的启示用.是上一篇下拉载入的扩展.先看一下那个再看这个就easy非常多. Dome下载:http://d ...
- 微信小程序 上拉刷新/下拉加载
小程序项目中上拉刷新下拉加载是比较常见的需求,官方文档也提供了相当友好的API,但是因为API隐藏的比较深,文档描述也比较模糊所以也折腾了一番(官方文档),在此记录一下使用方式 onPullDownR ...
- JQuery实现无刷新下拉加载图片
最近做的一个项目需要做页面无刷新下拉加载图片,调研了一番,大多都采用检测滚动条达到底部,然后利用ajax加载下一页数据对页面数据进行添加,根据这一逻辑,自己写了一个,具体代码如下: JQu ...
- Arduino 极速入门系列 - 光控灯(2) - 关于开关,上拉、下拉电阻那些事
接上篇,这次继续讲解光控灯的另外两个组成部分 - 开关和光敏电阻,光控灯里面将会有自锁开关按钮和光敏电阻.这此主要给新玩电子的朋友解释一下开关按钮的做法. 开关按钮的引脚电平读取问题 - 新手专用 我 ...
随机推荐
- IIS WMI Provider
section contains information about the classes that are implemented by the IIS WMI provider in the M ...
- WPF中使用MVVM模式进行简单的数据绑定
计划慢慢整理自己在WPF学习和工作应用中的一些心得和想法,先从一个简单的用法说起 在WPF中,XAML标记语言中绑定数据,而数据源就是指定为ViewModel类,而非界面本身的逻辑代码类 这样一定程度 ...
- Careercup - Facebook面试题 - 6204973461274624
2014-05-02 02:28 题目链接 原题: I/P: N, k O/P: all subset of N with exactly K elements. eg: I/p: N = , K = ...
- 简单易用的导出文件(Excel、word等各种格式)的方法
以前学习过NPOI导出数据到Excel中,代码较长,不易记忆.工作中,看到了其他同事写的代码,研究了一下,贴出来,共同学习. 使用这种方式,不仅可以设置表格的样式,而且代码简洁. 首先,在后台中通过S ...
- ffmpeg 从视频流中抓取图片
从视频中不断抓取图片的基本流程:打开视频流地址->获取视频流packt->解码成图片帧->输出图片 一.初始化Ffmpeg void ffmpegInit(){ av_registe ...
- MST性质(用于构造最小生成树)
描述:假设N=(V,{E})是一个连通网,U是顶点集V的一个非空子集.若(u,v)是一条具有最小权值(代价)的边,其中u∈U,v∈V-U,则必存在一棵包含边(u,v)的最小生成树. 证明: 假设网N的 ...
- 推荐acm题目
杭电 http://acm.hdu.edu.cn/onlineuser.php. 浙大 http://acm.zju.edu.cn/onlinejudge/submit.do?problemId= ...
- 2014 Multi-University Training Contest 8
官方解题报告:http://blog.sina.com.cn/s/blog_a19ad7a10102uzj7.html Area of Mushroom http://acm.hdu.edu.cn/s ...
- list 去掉重复的值
去除List列表中重复值(3种解决方法)public static void main(String[] args) { String[] ar = { "dd", "c ...
- Unity3D 游戏开发构架篇 ——角色类的设计与持久化
在游戏开发中,游戏角色占了很大的篇幅,可以说游戏中所有的内容都是由主角所带动.这里就介绍一下角色类的设计和持久化. 一.角色类应用场景和设计思想 游戏中的角色类型不一而足,有不同的技能,有不同的属性等 ...