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) - 关于开关,上拉、下拉电阻那些事
接上篇,这次继续讲解光控灯的另外两个组成部分 - 开关和光敏电阻,光控灯里面将会有自锁开关按钮和光敏电阻.这此主要给新玩电子的朋友解释一下开关按钮的做法. 开关按钮的引脚电平读取问题 - 新手专用 我 ...
随机推荐
- MVC的小知识点
1.MVC的前台页面编译完之后,也会生成一个前台页面类.在前天页面中加入这段代码this.GetType().Assembly.GetLocation()得到当前类所在的程序集,可以查看其所在的程序, ...
- Entity Framework学习笔记(六)----使用Lambda查询Entity Framework(1)
请注明转载地址:http://www.cnblogs.com/arhat 在前几章中,老魏一直使用Linq来查询Entity Framework.但是老魏感觉,如果使用Linq的话,那么Linq的返回 ...
- Notes of the scrum meeting(10/30)
meeting time:9:30~11:30p.m.,October 29th,2013 meeting place:20公寓楼前 attendees: 顾育豪 ...
- Qt入门之信号与槽机制
一. 简介 就我个人来理解,信号槽机制与Windows下消息机制类似,消息机制是基于回调函数,Qt中用信号与槽来代替函数指针,使程序更安全简洁. 信号和槽机制是 Qt 的核心机制,可以让编程人员将互不 ...
- SVN检出资源文件
一.选择new,输入svn,点击“从SVN检出项目” 二.选择“创建新的资源库位置”或“使用现有的资源库位置”(如果是新建,则需要地址和用户名.密码) 三.从现有的资源库选中项目
- 设置DIV隐藏与显示,表格滑动条
问题描述: 现在希望使用JS设置DIV块的显示与隐藏,当某一个事件触发是,自动显示DIV块,显示表格数据,但是要求表格显示滑动条 问题解决: (1)DIV块的隐藏与显示 如上所示, ...
- C# 数据结构--排序[上]
概述 看了几天的排序内容,现在和大家分享一些常见的排序方法. 啥是排序? 个人理解的排序:通过对数组中的值进行对比,交换位置最终得到一个有序的数组.排序分为内存排序和外部排序.本次分享排序方法都为内存 ...
- 20160725noip模拟赛“Paodekuai” alexandrali
T1: 我们可以用火柴棒来表示十进制下的0~9, 如图所示 现给定火柴数n, 问用这n根火柴能组成的最小数和最大数分别是多少. 所有火柴必须全部用完, 并且所有数字必须是正的且不含前缀零. [解题] ...
- jQuery插件手把手教会(二)
上次我们将到了简单的jQuery插件,这次我们继续: 面向对象的插件开发 为什么要有面向对象的思维,因为如果不这样,你可能需要一个方法的时候就去定义一个function,当需要另外一个方法的时候,再去 ...
- centos在yum install报错:Another app is currently holding the yum lock解决方法
centos在yum install报错:Another app is currently holding the yum lock,这个问题可能是很多的新手经常遇到问题,之前也有人问我,包括本人在刚 ...