PullToRefresh的使用

本文详细介绍了如何在Android应用中使用PullToRefresh库实现下拉刷新功能,包括导入库、XML布局配置及属性设置,并提供了代码示例。重点突出下拉刷新的实现步骤和关键属性配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

作者对使用方法介绍的很简单。详见: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",再进行具体属性的设置。举例如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:myns="http://schemas.android.com/apk/res/com.example.pullrefreshdemo"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
    
	<com.handmark.pulltorefresh.library.PullToRefreshListView
	    android:id="@+id/pull_to_refresh_listview"
	    android:layout_height="fill_parent"
	    android:layout_width="fill_parent"
	    myns:ptrMode="both"
	    myns:ptrAnimationStyle="flip"/>         <!-- 允许下拉刷新的方向和刷新样式 -->
</LinearLayout>

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

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

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值