CommonPullToRefresh

Android widget with pull to refresh for all the views,and support loadMore for ListView,RecyclerView,GridView and SwipeRefreshLayout.

android-Ultra-Pull-To-Refresh的基础上增加了加载更多的支持,感谢作者

Demo APK下载

ListView、RecyclerView截图

GridView截图

SwipeRefreshLayout截图

Usage

Gradle / Android Studio

compile 'com.chanven.lib:cptr:1.1.0'

下拉刷新配置

有6个参数可配置:

上面是在java代码中配置,也可在xml文件中配置
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.chanven.lib.cptr.PtrClassicFrameLayout
        android:id="@+id/test_list_view_frame"
        xmlns:cube_ptr="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#f0f0f0"
        cube_ptr:ptr_resistance="1.7"
        cube_ptr:ptr_ratio_of_header_height_to_refresh="1.2"
        cube_ptr:ptr_duration_to_close="200"
        cube_ptr:ptr_duration_to_close_header="1000"
        cube_ptr:ptr_keep_header_when_refresh="true"
        cube_ptr:ptr_pull_to_fresh="false">

        <ListView
            android:id="@+id/test_list_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"
            android:choiceMode="singleChoice"
            android:divider="#b0b0b0"
            android:dividerHeight="0.1dp"
            android:fadingEdge="none"
            android:scrollbarStyle="outsideOverlay"/>
    </com.chanven.lib.cptr.PtrClassicFrameLayout>

</LinearLayout>

处理刷新

通过PtrHandler,可以检查确定是否可以下来刷新以及在合适的时间刷新数据。

检查是否可以下拉刷新在PtrDefaultHandler.checkContentCanBePulledDown中有默认简单的实现,你可以根据实际情况完成这个逻辑。

public interface PtrHandler {
    /**
     * 检查是否可以执行下来刷新,比如列表为空或者列表第一项在最上面时。
     * <p/>
     * {@link com.chanven.lib.cptr.PtrDefaultHandler#checkContentCanBePulledDown}
     */
    public boolean checkCanDoRefresh(final PtrFrameLayout frame, final View content, final View header);

    /**
     * 需要加载数据时触发
     *
     * @param frame
     */
    public void onRefreshBegin(final PtrFrameLayout frame);
}

加载更多配置

Header、Footer样式

常见问题