android开发之PullToRefresh (GridView 下拉刷新,上拉加载)

本文详细介绍了在Android应用中如何实现GridView的下拉刷新和上拉加载功能。通过分析布局文件activity_main.xml和grid_item.xml,以及在MainActivity类中的关键代码,展示了自定义上下拉指示器文本内容的效果。同时,文章还探讨了如何显示时间以及如何通过XML布局文件调整刷新动画、禁止上拉等属性。提供了示例代码链接供读者参考。
摘要由CSDN通过智能技术生成

首先,看布局文件:

  • 主布局文件(activity_main.xml):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ptr="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff">

    <com.zanelove.gridviewpulltorefresh.library.PullToRefreshGridView
            android:id="@+id/pull_refresh_grid"
            android:columnWidth="100dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:numColumns="auto_fit"
            android:gravity="center_horizontal"
            android:horizontalSpacing="10dp"
            android:stretchMode="columnWidth"
            android:verticalSpacing="10dp"
            android:scrollbars="none"
            android:listSelector="@null"

            ptr:ptrAnimationStyle="flip"
            ptr:ptrHeaderBackground="#00000000"
            ptr:ptrHeaderSubTextColor="#999999"
            ptr:ptrHeaderTextColor="#333333"
            ptr:ptrListViewExtrasEnabled="false"
            ptr:ptrMode="both"
            ptr:ptrRefreshableViewBackground="#00000000"
            ptr:ptrScrollingWhileRefreshingEnabled="true"
            ptr:ptrShowIndicator="false"
            />
</RelativeLayout>
  • item布局文件(grid_item.xml):
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android=
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值