1、github下载地址

原作者:  https://github.com/chrisbanes/Android-PullToRefresh

我自己的:  https://github.com/zyj1609wz/Android-PullToRefresh

2、使用方法

listview  布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.aa.MainActivity"
tools:ignore="MergeRootFrame" >
<com.handmark.pulltorefresh.library.PullToRefreshListView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:listSelector="#00000000"
ptr:ptrMode="both" />
</LinearLayout>

常用的方法

package com.example.aa;
import java.util.ArrayList;
import java.util.List;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnLastItemVisibleListener;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import android.support.v7.app.ActionBarActivity;
import android.text.format.DateUtils;
import android.widget.ListView;
import android.widget.Toast;
import android.os.AsyncTask;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
PullToRefreshListView pullToRefreshListView  ;
ListView listView  ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pullToRefreshListView = (PullToRefreshListView) findViewById( R.id.listview ) ;
pullToRefreshListView.setOnRefreshListener( new OnRefreshListener<ListView>() {
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(),
DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL ) ;
//最后一次刷新的时间
refreshView.getLoadingLayoutProxy().setLastUpdatedLabel( "上次刷新时间   " + label);
//设置刷新图标 下拉的时候显示的内容
                refreshView.getLoadingLayoutProxy().setLoadingDrawable(getResources().getDrawable( R.drawable.ic_launcher) );
//下拉完成后,还没有刷新时 显示的内容
refreshView.getLoadingLayoutProxy().setReleaseLabel( "默默地么么哒!!" );
//松开手,正在刷新时 ,显示的内容
refreshView.getLoadingLayoutProxy().setRefreshingLabel(  "啦啦啦啦啦" );
Toast.makeText( MainActivity.this , "刷新了",  Toast.LENGTH_SHORT ).show();
new GetDataTask().execute(  ) ;
}
});
//listview 滑到 最后一项
pullToRefreshListView.setOnLastItemVisibleListener( new OnLastItemVisibleListener() {
@Override
public void onLastItemVisible() {
Toast.makeText( MainActivity.this , "listview到底了",  Toast.LENGTH_SHORT ).show() ;
}
});
pullToRefreshListView.setMode( Mode.PULL_FROM_START );
listView = pullToRefreshListView.getRefreshableView() ;
listView.setAdapter( new Adapter( this , getData() ));
/**
* 程序进来就执行刷新数据,自动执行刷新
*/
pullToRefreshListView.setRefreshing();
}
/**
* @author admin
*  pullToRefreshListView.onRefreshComplete();  这一句最好放在异步里面写
*
*/
private class GetDataTask extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
try {
Thread.sleep( 500 );
} catch (InterruptedException e) {
}
return "" ;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
pullToRefreshListView.onRefreshComplete();
}
}
List<String> getData(){
List<String> list = new ArrayList<String>() ;
for( int i = 0 ; i < 100 ; i ++) {
list.add( "ddd") ;
}
return list ;
}
}

刷新模式

    //向下拉
    pullToRefreshListView.setMode( Mode.PULL_FROM_START );
//向上拉
    pullToRefreshListView.setMode( Mode.PULL_FROM_END );
//同时使用 下拉  和 上拉
    pullToRefreshListView.setMode( Mode.BOTH );
/不启用刷新功能
pullToRefreshListView.setMode( Mode.DISABLED );

获取当前的刷新模式

//获取当前的刷新模式
if( pullToRefreshListView.getMode() == Mode.BOTH ){
Toast.makeText( MainActivity.this , "当前的刷新模式是 " + pullToRefreshListView.getMode() ,
Toast.LENGTH_SHORT ).show();
}

设置刷新时的声音

         /**
* Add Sound Event Listener
*/
SoundPullEventListener<ListView> soundListener = new SoundPullEventListener<ListView>(this);
soundListener.addSoundEvent(State.PULL_TO_REFRESH, R.raw.a1 );   //开始刷新显示的声音
soundListener.addSoundEvent(State.RESET, R.raw.a2 );             //刷新完成后,显示的声音
soundListener.addSoundEvent(State.REFRESHING, R.raw.a3 );        //正在刷新显示的声音
pullToRefreshListView.setOnPullEventListener(soundListener);

设置 下拉刷新 和 上拉加载 更多 的监听方法

    pullToRefreshListView.setOnRefreshListener( new Refresh() ) ;
/**
* 监听方法
* @author admin
*/
class Refresh implements OnRefreshListener2<ListView> {
//下拉
        @Override
public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
}
//上拉
        @Override
public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
}
}

设置正在刷新时,listview是否可以滚动

   //正在刷新的时候,listView 禁止滚动
pullToRefreshListView.setScrollingWhileRefreshingEnabled( false );
//正在刷新的时候,listView 可以滚动
pullToRefreshListView.setScrollingWhileRefreshingEnabled( true );

设置刷新时显示的字体的颜色

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.aa.MainActivity"
tools:ignore="MergeRootFrame" >
<com.handmark.pulltorefresh.library.PullToRefreshListView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/listview"
android:background="#ffffff"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:listSelector="#00000000"
ptr:ptrHeaderTextColor="#FF9900"
ptr:ptrHeaderSubTextColor="#330099"
ptr:ptrMode="both" />
<!-- ptrHeaderTextColor   刷新提示显示的颜色 -->
<!-- ptrHeaderSubTextColor 刷新提示子选项颜色值 -->
</LinearLayout>

运行结果

分别设置 下拉 和 上拉 显示的字体

        //得到下拉时候显示的ILoadingLayout
ILoadingLayout startLayout = pullToRefreshListView.getLoadingLayoutProxy( true , false ) ;
startLayout.setPullLabel("你可劲拉,拉...下拉");// 刚下拉时,显示的提示
startLayout.setRefreshingLabel("好嘞,正在刷新...下拉");// 刷新时
startLayout.setReleaseLabel("你敢放,我就敢刷新...下拉");// 下来达到一定距离时,显示的提示
//得到上拉时候显示的ILoadingLayout
ILoadingLayout endLayout = pullToRefreshListView.getLoadingLayoutProxy( false , true  ) ;
endLayout.setPullLabel("你可劲拉,拉... 上拉");// 刚下拉时,显示的提示
endLayout.setRefreshingLabel("好嘞,正在刷新...上拉");// 刷新时
endLayout.setReleaseLabel("你敢放,我就敢刷新...上拉");// 下来达到一定距离时,显示的提示 

常用的 xml 配置

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.aa.MainActivity"
tools:ignore="MergeRootFrame" >
<com.handmark.pulltorefresh.library.PullToRefreshListView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:gravity="center"
android:listSelector="#00000000"
ptr:ptrHeaderBackground="@drawable/background"
ptr:ptrHeaderSubTextColor="#330099"
ptr:ptrHeaderTextColor="#B26B00"
ptr:ptrListViewExtrasEnabled="false"
ptr:ptrMode="both"
ptr:ptrRefreshableViewBackground="@drawable/b2"
ptr:ptrRotateDrawableWhilePulling="false"
ptr:ptrScrollingWhileRefreshingEnabled="true"
ptr:ptrShowIndicator="true" />
<!-- ptrHeaderTextColor   刷新提示显示的颜色 -->
<!-- ptrHeaderSubTextColor 刷新提示子选项颜色值 -->
<!-- ptr:ptrHeaderBackground 上拉背景图 -->
<!-- ptrShowIndicator    右上角显示的小图标 -->
<!-- ptrRefreshableViewBackground  整个listview的背景 -->
<!-- ptrScrollingWhileRefreshingEnabled  刷新的时候,是否允许ListView或GridView滚动。觉得为true比较好。 -->
<!-- ptrListViewExtrasEnabled  Footer以何种方式加入mPullRefreshListView,true为headView方式加入,就是滚动时刷新头部会一起滚动。 -->
<!-- ptrRotateDrawableWhilePulling  当动画设置为rotate时,下拉是是否旋转。 -->
<!-- ptr:ptrAnimationStyle  的取值:flip(翻转动画), rotate(旋转动画) 。 -->
<!-- ptr:ptrDrawable  则就是设置图标了。 -->
</LinearLayout>

运行结果

 3、不太常用的东西

1、如何 关闭 log 日志输出 ?

PullToRefresh 默认是开启日志输出的 。 在  PullToRefreshBase 里面可以看到 static final boolean DEBUG = true ;

true : 输出日志 。   false : 不输出日志

android Android-PullToRefresh 下拉刷新相关推荐

  1. android自带下拉阻尼动画,android 有阻尼下拉刷新列表的实现方法

    本文将会介绍有阻尼下拉刷新列表的实现,先来看看效果预览: 这是下拉状态: 这是下拉松开手指后listView回滚到刷新状态时的样子: 1. 如何调用 虽然效果图看起来样子不太好看,主要是因为那个蓝色的 ...

  2. android 下拉刷新实现方式,Android RecyclerView设置下拉刷新的实现方法

    Android RecyclerView设置下拉刷新的实现方法 1 集成 SwipeRefreshLayout 1.1 xml布局文件中使用 android:id="@+id/refresh ...

  3. android中上拉下滑布局,3年以上勿进!最简单的Android自定义ListView下拉刷新与上拉加载,代码直接拿去用~...

    本文主要针对开发新手,手写实现一个最简单Android自定义listview下拉刷新和上拉加载demo. 不喜可喷,欢迎大佬留言指点. 效果图 一:编写需要在ListView中增加头加载的布局文件,与 ...

  4. android 设置下拉刷新,Android RecyclerView设置下拉刷新的实现方法

    Android RecyclerView设置下拉刷新的实现方法 1 集成 SwipeRefreshLayout 1.1 xml布局文件中使用 android:id="@+id/refresh ...

  5. Android-设置PullToRefresh下拉刷新样式

    Android-设置PullToRefresh下拉刷新样式 以下是开源控件PullToRefresh的自定义样式属性: <?xml version="1.0" encodin ...

  6. Android ListView 实现下拉刷新上拉加载

    转载请注明出处:http://blog.csdn.net/allen315410/article/details/39965327 1.简介 无疑,在Android开发中,ListView是使用非常频 ...

  7. Android自定义控件实战——下拉刷新控件终结者:PullToRefreshLayout

    说到下拉刷新控件,网上版本有很多,很多软件也都有下拉刷新功能.有一个叫XListView的,我看别人用过,没看过是咋实现的,看这名字估计是继承自ListView修改的,不过效果看起来挺丑的,也没什么扩 ...

  8. 浅谈Android列表ListView下拉刷新控件的实现(一)

    ListView下拉刷新的功能到处可见,很多app客户端都存在,比如QQ空间好友动态下拉刷新,网易新闻内容下拉刷新等.相信很多人已经把这个功能运用的很溜,妥妥的吧,接下就来实现一下功能,有个不爽的一点 ...

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

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

  10. Android RecyclerView封装下拉刷新与上拉加载更多

    1 scanlistlibrary 基础组件说明(基于 RecyclerView的封装) 基本数据列表(支持下拉刷新与上拉加载更多) 九宫格数据显示封装(支持下拉刷新与上拉加载更多) 瀑布流数据显示封 ...

最新文章

  1. 【游戏开发】基于VS2017的OpenGL开发环境搭建
  2. php计算属性集的闭包,关于swift:计算属性与带闭包的属性集之间的区别
  3. 幸福在《精通移动App测试实战 技术、工具和案例》
  4. java 反射创建对象并赋值_[原创] Java JDBC连接数据库,反射创建实体类对象并赋值数据库行记录(支持存储过程)...
  5. 15款最佳的 jQuery 分步引导插件
  6. 了解链表和二叉树的结构
  7. ubuntu16.04下编译安装Autoware
  8. C++ Primer中英文版 (第5版)
  9. win10如何录制内部声音(非麦克风录音)
  10. 邮件系统html源码,SpringBoot系列—简单的邮件系统(附完整项目代码)
  11. 什么是python元祖_python元组
  12. 公众号如何涨粉?会其中一种都可以让你爆粉
  13. html如何设置banner,css设置banner图自适应的方法
  14. PHP乘法表菜鸟教程,第二节 菜鸟教程的实例
  15. 3.17 inappropriateintimacy (狎昵关系)
  16. 片上总线Wishbone 学习(一)片上总线综述
  17. 我的Android进阶之旅------Android通过调用Webservice实现天气预报
  18. Tables[0].Rows.count是什么意思
  19. 筛选后系列填充_不会用Excel做数据筛选,老板叼的你没话说!
  20. vscode代码格式化、vetur代码格式化取消末尾添加逗号

热门文章

  1. map集合怎么取value值最大的前三_Java之集合(下)
  2. pytorch Tensor的操作和Numpy之间的转化(三)
  3. SIGIR 2019 eBay高精度召回任务挑战赛冠军团队DeepBlueAI技术分享
  4. NeuSomatic:基于深度CNN的肿瘤体细胞突变检测工具
  5. 本周 Github 精选:13 款炼丹利器,有开源工具包也有超大数据集
  6. 基于对偶学习的跨领域图片描述生成
  7. web第一节2020.5.11
  8. Pytorch中DataLoader类
  9. greaterT()和lessT()
  10. handler原子锁_深入Linux内核架构——锁与进程间通信