A custom SwipeRefreshLayout to support the pull-to-refresh featrue.RecyclerView,ListView,GridView,NestedScrollView,ScrollView are supported.

Overview

SuperSwipeRefreshLayout

A custom SwipeRefreshLayout to support the pull-to-refresh featrue.You can custom your header view and footer view. RecyclerView,ListView,GridView,NestedScrollView,ScrollView are supported.

aar

allprojects {
    repositories {
        jcenter()
        maven {
            url  "http://dl.bintray.com/nuptboyzhb/maven"
        }
    }
}
compile 'com.github.nuptboyzhb.lib.uikit:superswiperefreshlayout:1.0.0'

Feature

  • 支持下拉刷新和上拉加载更多,使用极其方便。
  • 非侵入式,对原来的ListView、RecyclerView没有任何影响,用法和SwipeRefreshLayout类似。
  • 可自定义头部View的样式,调用setHeaderView方法即可。
  • 可自定义页尾View的样式,调用setFooterView方法即可。
  • 支持RecyclerView,ListView,ScrollView,GridView,NestedScrollView等等。
  • 被包含的View(RecyclerView,ListView etc.)可跟随手指的滑动而滑动
    默认是跟随手指的滑动而滑动,也可以设置为不跟随:setTargetScrollWithLayout(false)
  • 回调方法更多
    比如:onRefresh() onPullDistance(int distance)和onPullEnable(boolean enable)
    开发人员可以根据下拉过程中distance的值做一系列动画。

Pull To Refresh(How to Use)

Step 1: In XML

<com.github.nuptboyzhb.lib.SuperSwipeRefreshLayout
		android:id="@+id/swipe_refresh"
		android:layout_width="match_parent"
		android:layout_height="match_parent" >

		<android.support.v7.widget.RecyclerView
			android:id="@+id/recycler_view"
			android:layout_width="match_parent"
			android:layout_height="match_parent" />
</com.github.nuptboyzhb.lib.SuperSwipeRefreshLayout>

Step 2: Init and setListener

swipeRefreshLayout = (SuperSwipeRefreshLayout) findViewById(R.id.swipe_refresh);
		swipeRefreshLayout.setHeaderView(createHeaderView());// add headerView
		swipeRefreshLayout
				.setOnPullRefreshListener(new OnPullRefreshListener() {

					@Override
					public void onRefresh() {
						//TODO 开始刷新
					}

					@Override
					public void onPullDistance(int distance) {
						//TODO 下拉距离
					}

					@Override
					public void onPullEnable(boolean enable) {
						//TODO 下拉过程中,下拉的距离是否足够出发刷新
					}
				});

加载完成之后: swipeRefreshLayout.setRefresh(false);

More


以上已经能够满足大部分需求,当然,你也可以这样:
  • Customized your header view
    自定义自己的下拉刷新头部View
swipeRefreshLayout.setHeaderView(createHeaderView());// add headerView

/**
 * create Header View
 */
private View createHeaderView(){
   //TODO 创建下拉刷新头部的View样式
}
  • setTargetScrollWithLayout(false/true);//default true
    设置下拉时,被包含的View是否随手指的移动而移动
swipeRefreshLayout.setTargetScrollWithLayout(true);
  • setHeaderViewBackgroundColor
    设置下拉刷新头部背景色
swipeRefreshLayout.setHeaderViewBackgroundColor(0xff888888);
  • setDefaultCircleProgressColor
    设置默认圆形进度条颜色

  • setDefaultCircleBackgroundColor
    设置默认圆形背景色

  • setDefaultCircleShadowColor
    设置默认圆形的阴影颜色

  • setEnable
    设置是否禁用下拉刷新,默认是使用

Push to Load More

当拉倒底部时,上拉加载更多

setListener

swipeRefreshLayout
				.setOnPushLoadMoreListener(new OnPushLoadMoreListener() {

					@Override
					public void onLoadMore() {
						...
						new Handler().postDelayed(new Runnable() {

							@Override
							public void run() {
								...
                                //set false when finished
								swipeRefreshLayout.setLoadMore(false);
							}
						}, 5000);
					}

					@Override
					public void onPushEnable(boolean enable) {
						//TODO 上拉过程中,上拉的距离是否足够出发刷新
					}

					@Override
					public void onPushDistance(int distance) {
						// TODO 上拉距离

					}

				});

Customized your footer view

swipeRefreshLayout.setFooterView(createFooterView());

Support View

  • RecyclerView.
  • ListView
  • SrcollView
  • GridView
  • etc.

Demo

gif

About

@Author: Zheng Haibo 莫川
@Website: https://github.com/nuptboyzhb

License

Copyright 2015-2016 Zheng Haibo

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Comments
  • 当item的布局高度大于recyclerview的高度时,无法调用onLoadMore方法

    当item的布局高度大于recyclerview的高度时,无法调用onLoadMore方法

    当item的布局高度大于recyclerview的高度(单个item无法完整地显示在屏幕中)时,无法调用onLoadMore方法 因为findLastCompletelyVisibleItemPosition返回了-1 改为findLastVisibleItemPosition可以,但是会出现该item没有出来完成loadmore动画已经覆盖了该item

    opened by chendiyou 3
  • 上下拉时崩溃问题

    上下拉时崩溃问题

    先上拉加载之后,再去下拉刷新,应用崩溃,demo也存在这个问题,然后studio中给出的错误位置是在onLayout()中的 child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);// 更新目标View的位置,错误原因是说数组下标越界。希望大神们帮助解决一下,谢谢啦

    opened by glmsb 2
  • 不适用个人界面布局?

    不适用个人界面布局?

    设计是这样的。 CustomSwipeRefreshLayout - > Header - > RecyclerView 其中header是不跟着RecyclerView,下拉刷新的时候 !ViewCompat.canScrollVertically(mTarget, -1); 这句话有问题,应该怎么修改会比较好呢?

    opened by chendiyou 1
  • NestedScrollView监听不到

    NestedScrollView监听不到

    需要添加下面代码 else if (mTarget instanceof NestedScrollView){ NestedScrollView nestedScrollView = (NestedScrollView) mTarget; View view = (View) nestedScrollView.getChildAt(nestedScrollView.getChildCount() - 1); if (view != null) { int diff = (view.getBottom() - (nestedScrollView.getHeight() + nestedScrollView.getScrollY())); if (diff == 0) { return true; } } }

    opened by Reginer 1
  • [modify]修复mHeadViewContainer及mFooterViewContainer宽度没有正确计算的问题

    [modify]修复mHeadViewContainer及mFooterViewContainer宽度没有正确计算的问题

    使用中发现在父布局中margin或者padding的情况下,底部(可能头部也是这样的)view会被挡住部分,查看里面实现发现是将mFooterViewContainer和mHeaderViewContainer的宽度都是以屏幕宽度作为自己的宽度的,这里稍微可以改进一下,在onMeasure方法中进行了部分修改

    opened by chniccs 0
  • 在CoordinatorLayout + AppBarLayout 可折叠式结构中,控件失效

    在CoordinatorLayout + AppBarLayout 可折叠式结构中,控件失效

    XML具体结构:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@drawable/shap_line"
        android:orientation="vertical"
        android:showDividers="middle">
    
        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">
    
            <android.support.design.widget.AppBarLayout
                android:id="@+id/appbar_main"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clipToPadding="false"
                android:fitsSystemWindows="true"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar_main"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:layout_marginBottom="6dp"
                    android:background="?attr/colorPrimary"
                    app:layout_scrollFlags="scroll|enterAlways"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    
    
                <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
                    android:id="@+id/search_card"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="8dp"
                    android:layout_marginLeft="12dp"
                    android:layout_marginRight="12dp"
                    android:layout_marginTop="8dp"
                    android:clickable="true"
                    android:foreground="@drawable/ripple_press"
                    card_view:cardBackgroundColor="@color/bg_card"
                    card_view:cardCornerRadius="1dp"
                    card_view:cardElevation="2dp"
                    card_view:contentPadding="8dp">
    
                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:scaleType="fitCenter"
                        android:src="@drawable/ic_search_black_24dp" />
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_marginLeft="28dp"
                        android:singleLine="true"
                        android:text="@string/search_line_or_station"
                        android:textColor="@color/text_primary_dark"
                        android:textSize="18sp"
                        android:textStyle="bold" />
    
    
                    <TextView
                        android:id="@+id/text_location_tag"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical|right"
                        android:background="@color/accent_deep_orange_700"
                        android:drawableLeft="@drawable/ic_my_location_white_18dp"
                        android:padding="2dp"
                        android:text=""
                        android:textColor="@color/text_primary"
                        android:textSize="16sp" />
    
                </android.support.v7.widget.CardView>
    
    
            </android.support.design.widget.AppBarLayout>
    
            <com.gongjiao.rr.dawn.widget.SuperSwipeRefreshLayout
                android:id="@+id/swipe_refresh_main"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recycler_main"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:divider="@android:color/transparent"
                    android:dividerHeight="10dp"
                    android:listSelector="@android:color/transparent"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    
    
            </com.gongjiao.rr.dawn.widget.SuperSwipeRefreshLayout>
    
        </android.support.design.widget.CoordinatorLayout>
    
        <include layout="@layout/statebar_waiting"></include>
        <include layout="@layout/statebar_running"></include>
    </LinearLayout>
    
    opened by taosimple 0
  • use custom header may lead a bug

    use custom header may lead a bug

    i use this awesome layout in my project , everything is fine, except top part(exactly the default header's head) of the page would been hide util i touch this layout, i use my custom swipe refresh header, so i debug and found in onlayout() method something may lead this bug. Signed-off-by: muxims3 [email protected]

    opened by muximus3 0
  • 刷新时报错:pointerIndex out of range pointerIndex=-1 pointerCount=1

    刷新时报错:pointerIndex out of range pointerIndex=-1 pointerCount=1

    请问这个问题怎么解决?下面是Log:

    java.lang.IllegalArgumentException: pointerIndex out of range pointerIndex=-1 pointerCount=1 at android.view.MotionEvent.nativeGetAxisValue(Native Method) at android.view.MotionEvent.getY(MotionEvent.java:2087) at android.support.v4.view.MotionEventCompat.getY(MotionEventCompat.java:521) at com.mddjob.android.view.ptr.SuperSwipeRefreshLayout.handlerPullTouchEvent(SuperSwipeRefreshLayout.java:920) at com.mddjob.android.view.ptr.SuperSwipeRefreshLayout.onTouchEvent(SuperSwipeRefreshLayout.java:819) at android.view.View.dispatchTouchEvent(View.java:9399) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2523) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2240) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2525) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2525) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2525) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2525) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2525) at android.view.ViewGroup.cancelAndClearTouchTargets(ViewGroup.java:2375) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3051) at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:3186) at

    opened by GsBu 2
  • 无法拉取依赖

    无法拉取依赖

    Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.github.nuptboyzhb.lib.uikit:superswiperefreshlayout:1.0.0.

    opened by chat491231702 2
  • 用travis CI进行自动发布release时,会出错

    用travis CI进行自动发布release时,会出错

    • What went wrong: A problem occurred configuring project ':app'.

    Could not resolve all dependencies for configuration ':app:_debugApkCopy'. Could not resolve com.github.nuptboyzhb.lib.uikit:superswiperefreshlayout:1.0.0. Required by: project :app > Could not resolve com.github.nuptboyzhb.lib.uikit:superswiperefreshlayout:1.0.0. > Could not get resource 'http://dl.bintray.com/nuptboyzhb/maven/com/github/nuptboyzhb/lib/uikit/superswiperefreshlayout/1.0.0/superswiperefreshlayout-1.0.0.pom'. > Could not GET 'http://dl.bintray.com/nuptboyzhb/maven/com/github/nuptboyzhb/lib/uikit/superswiperefreshlayout/1.0.0/superswiperefreshlayout-1.0.0.pom'. > Connect to 127.0.0.1:1080 [/127.0.0.1] failed: Connection refused (Connection refused)

    以上是travis build的log信息,travis build时是用的它自己的proxy,好像墙了这个地址,要怎么解决?

    opened by liujunlingx 0
Owner
Zheng Haibo(莫川)
Staff Engineer in Alibaba Group
Zheng Haibo(莫川)
This component like SwipeRefreshLayout, it is more beautiful than SwipeRefreshLayout.

android-PullRefreshLayout This component like SwipeRefreshLayout, it is more beautiful than SwipeRefreshLayout. Demo Usage Add dependency. dependencie

星一 2.1k Dec 3, 2022
Ultra Pull to Refresh for Android. Support all the views.

Welcome to follow me on GitHub or Twitter GitHub: https://github.com/liaohuqiu Twitter: https://twitter.com/liaohuqiu 中文版文档 Wanna auto-load-more? This

Huqiu Liao 9.6k Jan 5, 2023
a custom pull-to-refresh layout which contains a interesting animation

This is a project with custom pull-to-refresh layout which contains a interesting animation. And the animation is inspired by https://dribbble.com/sho

ZhangLei 1.8k Dec 27, 2022
Phoenix Pull-to-Refresh

Phoenix Pull-to-Refresh This project aims to provide a simple and customizable pull to refresh implementation. Made in [Yalantis] (https://yalantis.co

Yalantis 4k Dec 30, 2022
A little more fun for the pull-to-refresh interaction.

Pull-to-Refresh.Tours This project aims to provide a simple and customizable pull to refresh implementation. Check this [project on Behance] (https://

Yalantis 1.7k Dec 24, 2022
A pull-down-to-refresh layout inspired by Lollipop overscrolled effects

JellyRefreshLayout A pull-down-to-refresh layout inspired by Lollipop overscrolled effects Preview Download Gradle: repositories { maven {

Y.Chen 628 Oct 26, 2022
Implementation of ExpandableListview with custom header and custom content.

ExpandableLayout ExpandableLayout provides an easy way to create a view called header with an expandable view. Both view are external layout to allow

Robin Chutaux 1.6k Dec 12, 2022
类似 iOS 带弹簧效果的左右滑动控件,可作为 AbsListView 和 RecyclerView 的 item(作为 AbsListView 的 item 时的点击事件参考代码家的 https://github.com/daimajia/AndroidSwipeLayout )

?? BGASwipeItemLayout-Android ?? 类似iOS带弹簧效果的左右滑动控件,可作为AbsListView和RecyclerView的item。支持给BGASwipeItemLayout和其子控件设置margin和padding属性 效果图 Gradle依赖 dependen

王浩 469 Dec 9, 2022
Smooth version of Google Support Design AppBarLayout

smooth-app-bar-layout [Deprecated] ================ [DEPRECATED] The issue that is addressed in this library is fixed from support design 26.0.0 or ab

Henry Tao 1.8k Dec 13, 2022
A simple customised version of the TextInputLayout from the Android Design Support Library ⌨️

Buffer Text Input Layout (Coming to maven central soon!) This is a simple customisation of the TextInputLayout found in the Design Support Library. Wh

Buffer 988 Nov 24, 2022
Added support to modify text size and indicator width based on the original TabLayout.

XTabLayout——可修改选中项字体大小和指示器长度的TabLayout XTabLayout是基于design包中的TabLayout进行了功能的扩展,在保留原有功能的基础上,增加了修改选中项字体大小、修改指示器长度以及限制屏幕显示范围内显示的Tab个数。 集成步骤: 1.添加XTabLayo

Kennor 660 Dec 20, 2022
GoolgePlusLayout is a custom layout that plays animation on the children views while scrolling as the layout in the Google Plus (android) main page

Google Plus Layout Google Plus Layout is a custom layout that support playing animation on child view(s) in a serialize manner like the the main

Ahmed Nammari 224 Nov 25, 2022
null 2.4k Dec 30, 2022
A custom ViewPager title strip which gives continuous feedback to the user when scrolling

SmartTabLayout A custom ViewPager title strip which gives continuous feedback to the user when scrolling. This library has been added some features an

ogaclejapan 7k Jan 7, 2023
CircularStats - Custom Widget to display stats of any thing

CircularStats This is a custom widget made with Jetpack Compose for displaying s

null 14 Jul 2, 2022
Android widget with pull to refresh for all the views,and support loadMore for ListView , RecyclerView, GridView and SwipeRefreshLayout.

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

null 1.1k Nov 10, 2022
An Android Library that allows users to pull down a menu and select different actions. It can be implemented inside ScrollView, GridView, ListView.

AndroidPullMenu AndroidPullMenu is an Open Source Android library that allows developers to easily create applications with pull menu. The aim of this

Armando TBA 181 Nov 29, 2022
A pull to refresh layout for android, the RecyclerRefreshLayout is based on the SwipeRefreshLayout. support all the views, highly customizable, code simplicity, etc. really a practical RefreshLayout!

RecyclerRefreshLayout English | 中文版 RecyclerRefreshLayout based on the {@link android.support.v4.widget.SwipeRefreshLayout} The RecyclerRefreshLayout

dinus_developer 1.7k Nov 10, 2022