Android下拉刷新的实现---pulltorefresh

作者对使用方法介绍的很简单。详见:https://github.com/chrisbanes/Android-PullToRefresh/wiki/Quick-Start-Guide

我这里写一下自己的一些收获:

1. 导入PullToRefresh库,方法详见 http://developer.android.com/tools/projects/projects-eclipse.html#ReferencingLibraryProject

2.  在写xml文件时,先声明name spase:xmlns:myns="http://schemas.android.com/apk/res/com.example.pullrefreshdemo",再进行具体属性的设置。举例如下:

[html] view plaincopy
 
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     xmlns:myns="http://schemas.android.com/apk/res/com.example.pullrefreshdemo"  
  4.     android:orientation="vertical"  
  5.     android:layout_width="match_parent"  
  6.     android:layout_height="match_parent"  
  7.     tools:context=".MainActivity" >  
  8.   
  9.     <TextView  
  10.         android:layout_width="wrap_content"  
  11.         android:layout_height="wrap_content"  
  12.         android:text="@string/hello_world" />  
  13.       
  14.     <com.handmark.pulltorefresh.library.PullToRefreshListView  
  15.         android:id="@+id/pull_to_refresh_listview"  
  16.         android:layout_height="fill_parent"  
  17.         android:layout_width="fill_parent"  
  18.         myns:ptrMode="both"  
  19.         myns:ptrAnimationStyle="flip"/>         <!-- 允许下拉刷新的方向和刷新样式 -->  
  20. </LinearLayout>  


注意,因为已经引入了pulltorefresh库,所以xmlns写自己的packname就行。不需要写com.handmark.pulltorefresh.library

具体哪些attr可用,可以参考源代码中的values/attrs.xml文件。attrs的具体原理可以参考这篇博文:http://blog.csdn.net/jincf2011/article/details/6344678

3. 如果ptrMode定义为both,即允许从上而下和从下而上2个方向进行拉动刷新,应该使用 public final void setOnRefreshListener(OnRefreshListener2<T> listener)  这个函数来设定listener

原文: http://blog.csdn.net/flybywind/article/details/8977734

原文地址:https://www.cnblogs.com/veins/p/3714127.html