Convert Figma logo to code with AI

dkzwm logoSmoothRefreshLayout

一款支持上下拉刷新、越界回弹、二级刷新、横向刷新、拉伸回弹、平滑滚动、嵌套滚动的多功能刷新控件

1,301
218
1,301
6

Top Related Projects

🔥下拉刷新、上拉加载、二级刷新、淘宝二楼、RefreshLayout、OverScroll,Android智能下拉刷新框架,支持越界回弹、越界拖动,具有极强的扩展性,集成了几十种炫酷的Header和 Footer。

Ultra Pull to Refresh for Android. Support all the views.

4,015

Phoenix Pull-to-Refresh

DEPRECATED

A reusable pull-to-refresh and pull-to-loadmore widget

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!

Quick Overview

SmoothRefreshLayout is an Android library that provides a customizable pull-to-refresh layout for implementing smooth scrolling and refreshing effects in Android applications. It supports both vertical and horizontal orientations, and offers a wide range of customization options for refresh indicators and animations.

Pros

  • Highly customizable with support for various refresh indicators and animations
  • Supports both vertical and horizontal orientations
  • Smooth scrolling and refreshing effects
  • Compatible with most scrollable views (e.g., ListView, RecyclerView, ScrollView)

Cons

  • Steeper learning curve compared to simpler pull-to-refresh libraries
  • May require more setup and configuration for complex use cases
  • Documentation could be more comprehensive for advanced features
  • Some reported issues with nested scrolling in certain scenarios

Code Examples

  1. Basic implementation with a ListView:
val refreshLayout = findViewById<SmoothRefreshLayout>(R.id.refresh_layout)
val listView = findViewById<ListView>(R.id.list_view)

refreshLayout.setOnRefreshListener {
    // Perform refresh operation
    refreshLayout.refreshComplete()
}

refreshLayout.autoRefresh() // Trigger refresh programmatically
  1. Customizing the refresh header:
val refreshLayout = findViewById<SmoothRefreshLayout>(R.id.refresh_layout)
val customHeader = CustomRefreshHeader(context)

refreshLayout.setHeaderView(customHeader)
refreshLayout.setEnableHeaderDrawerStyle(true)
refreshLayout.setHeaderHeight(100f)
  1. Implementing horizontal refresh:
val refreshLayout = findViewById<SmoothRefreshLayout>(R.id.refresh_layout)
refreshLayout.setLayoutOrientation(SmoothRefreshLayout.HORIZONTAL)
refreshLayout.setEnableFooterDrawerStyle(true)
refreshLayout.setFooterView(CustomRefreshFooter(context))

Getting Started

To use SmoothRefreshLayout in your Android project:

  1. Add the dependency to your app's build.gradle file:

    implementation 'com.github.dkzwm:SmoothRefreshLayout:1.6.0'
    
  2. Add the SmoothRefreshLayout to your layout XML:

    <me.dkzwm.widget.srl.SmoothRefreshLayout
        android:id="@+id/refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <!-- Your scrollable view goes here -->
    
    </me.dkzwm.widget.srl.SmoothRefreshLayout>
    
  3. Initialize and configure the SmoothRefreshLayout in your Activity or Fragment:

    val refreshLayout = findViewById<SmoothRefreshLayout>(R.id.refresh_layout)
    refreshLayout.setOnRefreshListener {
        // Perform refresh operation
        refreshLayout.refreshComplete()
    }
    

Competitor Comparisons

🔥下拉刷新、上拉加载、二级刷新、淘宝二楼、RefreshLayout、OverScroll,Android智能下拉刷新框架,支持越界回弹、越界拖动,具有极强的扩展性,集成了几十种炫酷的Header和 Footer。

Pros of SmartRefreshLayout

  • More extensive customization options for header and footer styles
  • Larger community and more frequent updates
  • Better documentation and examples

Cons of SmartRefreshLayout

  • Slightly more complex implementation due to additional features
  • Larger library size, which may impact app size

Code Comparison

SmoothRefreshLayout:

SmoothRefreshLayout refreshLayout = findViewById(R.id.refresh_layout);
refreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {
    @Override
    public void onRefreshing() {
        // Refresh logic here
    }
});

SmartRefreshLayout:

RefreshLayout refreshLayout = findViewById(R.id.refreshLayout);
refreshLayout.setOnRefreshListener(new OnRefreshListener() {
    @Override
    public void onRefresh(RefreshLayout refreshlayout) {
        // Refresh logic here
    }
});

Both libraries offer similar basic functionality for implementing pull-to-refresh in Android applications. SmartRefreshLayout provides more built-in header and footer styles, making it easier to create visually appealing refresh animations. However, this comes at the cost of a slightly larger library size.

SmoothRefreshLayout offers a more lightweight solution with a simpler API, which may be preferable for projects with minimal customization needs. SmartRefreshLayout's larger community and more frequent updates can be beneficial for long-term support and feature additions.

In terms of implementation, both libraries have similar ease of use, with SmartRefreshLayout offering more options for customization out of the box.

Ultra Pull to Refresh for Android. Support all the views.

Pros of android-Ultra-Pull-To-Refresh

  • Simpler implementation with fewer configuration options
  • Lightweight and easy to integrate into existing projects
  • Well-documented with clear examples and usage instructions

Cons of android-Ultra-Pull-To-Refresh

  • Less customizable compared to SmoothRefreshLayout
  • Limited support for advanced features like nested scrolling
  • Not actively maintained (last update was several years ago)

Code Comparison

SmoothRefreshLayout:

mRefreshLayout = findViewById(R.id.smoothRefreshLayout);
mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {
    @Override
    public void onRefreshing() {
        // Refresh logic here
    }
});

android-Ultra-Pull-To-Refresh:

mPtrFrame = (PtrFrameLayout) findViewById(R.id.store_house_ptr_frame);
mPtrFrame.setPtrHandler(new PtrHandler() {
    @Override
    public void onRefreshBegin(PtrFrameLayout frame) {
        // Refresh logic here
    }
});

Both libraries offer similar basic functionality for implementing pull-to-refresh in Android applications. SmoothRefreshLayout provides more advanced features and customization options, making it suitable for complex projects. android-Ultra-Pull-To-Refresh, on the other hand, offers a simpler implementation that may be preferable for smaller projects or quick prototypes. However, its lack of recent updates may be a concern for long-term maintainability.

4,015

Phoenix Pull-to-Refresh

Pros of Phoenix

  • Visually appealing and customizable animations
  • Easy to implement with minimal setup
  • Lightweight library with a small footprint

Cons of Phoenix

  • Limited to pull-to-refresh functionality only
  • Less actively maintained compared to SmoothRefreshLayout
  • Fewer configuration options and customization features

Code Comparison

Phoenix implementation:

val refreshLayout = PullToRefreshView(this)
refreshLayout.setOnRefreshListener {
    // Refresh logic here
    refreshLayout.setRefreshing(false)
}

SmoothRefreshLayout implementation:

val refreshLayout = SmoothRefreshLayout(this)
refreshLayout.setOnRefreshListener {
    // Refresh logic here
    refreshLayout.refreshComplete()
}
refreshLayout.autoRefresh()

Summary

Phoenix offers a visually appealing and easy-to-implement pull-to-refresh solution, while SmoothRefreshLayout provides more comprehensive refresh and load-more functionality with extensive customization options. SmoothRefreshLayout is more actively maintained and offers a wider range of features, making it suitable for complex implementations. Phoenix is ideal for projects requiring a simple, attractive pull-to-refresh mechanism with minimal setup.

DEPRECATED

Pros of Android-PullToRefresh

  • Mature and well-established library with a large user base
  • Supports multiple view types (ListView, GridView, WebView, etc.)
  • Extensive documentation and examples available

Cons of Android-PullToRefresh

  • No longer actively maintained (last commit in 2015)
  • Limited customization options compared to newer libraries
  • Lacks support for modern Android features and Material Design

Code Comparison

Android-PullToRefresh:

PullToRefreshListView mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list);
mPullRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {
    @Override
    public void onRefresh(PullToRefreshBase<ListView> refreshView) {
        // Do work to refresh the list here
    }
});

SmoothRefreshLayout:

SmoothRefreshLayout mRefreshLayout = findViewById(R.id.refresh_layout);
mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {
    @Override
    public void onRefreshing() {
        // Do work to refresh the list here
    }
});

SmoothRefreshLayout offers a more modern and flexible approach to implementing pull-to-refresh functionality. It supports a wider range of customization options and is actively maintained, making it a better choice for new projects. However, Android-PullToRefresh may still be suitable for legacy applications or those requiring support for older Android versions.

A reusable pull-to-refresh and pull-to-loadmore widget

Pros of SwipeToLoadLayout

  • Simpler implementation with fewer customization options, making it easier to use for basic pull-to-refresh functionality
  • Lightweight library with a smaller footprint
  • Supports both pull-down-to-refresh and pull-up-to-load-more out of the box

Cons of SwipeToLoadLayout

  • Less flexible and customizable compared to SmoothRefreshLayout
  • Fewer animation options and visual styles available
  • Limited support for advanced features like nested scrolling or multi-directional refreshing

Code Comparison

SmoothRefreshLayout:

mRefreshLayout = findViewById(R.id.smoothRefreshLayout);
mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {
    @Override
    public void onRefreshing() {
        // Refresh logic here
    }
});

SwipeToLoadLayout:

swipeToLoadLayout = findViewById(R.id.swipeToLoadLayout);
swipeToLoadLayout.setOnRefreshListener(new OnRefreshListener() {
    @Override
    public void onRefresh() {
        // Refresh logic here
    }
});

Both libraries offer similar basic implementation, but SmoothRefreshLayout provides more advanced options for customization and configuration. SwipeToLoadLayout focuses on simplicity and ease of use for common pull-to-refresh scenarios.

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!

Pros of RecyclerRefreshLayout

  • Specifically designed for RecyclerView, providing optimized performance
  • Lightweight and focused on a single purpose, potentially easier to integrate
  • Supports both pull-down refresh and pull-up load more functionalities

Cons of RecyclerRefreshLayout

  • Less flexible compared to SmoothRefreshLayout, which supports multiple view types
  • May have fewer customization options for the refresh header and footer
  • Limited to RecyclerView, while SmoothRefreshLayout can work with various scrollable views

Code Comparison

SmoothRefreshLayout:

SmoothRefreshLayout refreshLayout = findViewById(R.id.refresh_layout);
refreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {
    @Override
    public void onRefreshing() {
        // Refresh logic here
    }
});

RecyclerRefreshLayout:

RecyclerRefreshLayout refreshLayout = findViewById(R.id.refresh_layout);
refreshLayout.setOnRefreshListener(new OnRefreshListener() {
    @Override
    public void onRefresh() {
        // Refresh logic here
    }
});

Both libraries offer similar basic usage, but SmoothRefreshLayout provides more extensive customization options and supports various view types, while RecyclerRefreshLayout is tailored specifically for RecyclerView implementations.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

SmoothRefreshLayout

Methods MinSdk License

English | 中文

一个高效的Android刷新库,理论上支持所有的视图,比官方的SwipeRefreshLayout更强大且使用方便.

特性:

  • 理论上支持所有的视图,且可根据具体需求高效适配.
  • 支持多点触摸.
  • 支持嵌套滑动,完整实现了NestedScrollingChild3,NestedScrollingParent3 接口,玩转CoordinatorLayout.
  • 直接继承自ViewGroup,拥有卓越的性能,支持类FameLayout的特性(Gravity、Margin).
  • 支持自动刷新、自动上拉加载、到底自动加载更多(不推荐,建议使用Adapter实现,可自定义到底判断逻辑回调实现预加载更多).
  • 支持越界回弹,支持基于物理特性的越界回弹效果.
  • 支持刷新视图自定样式:STYLE_DEFAULT(默认不改变大小)、STYLE_SCALE(动态改变大小,会在SRL内部测量并布局,所以性能会有损失)、STYLE_PIN(不会改变视图大小,固定在顶部或者底部)、STYLE_FOLLOW_SCALE(先纵向跟随移动并且不改变视图大小,大于视图高度后动态改变视图大小且性能会有损失)、STYLE_FOLLOW_PIN(不会改变视图大小,先纵向跟随移动,大于视图高度后固定)、STYLE_FOLLOW_CENTER(不会改变视图大小,先纵向跟随移动,大于视图高度后让视图保持在移动的距离中心点).
  • 支持二级刷新事件(TwoLevelSmoothRefreshLayout),PS:淘宝二楼、京东活动.
  • 支持横向刷新(HorizontalSmoothRefreshLayout).
  • 支持ListView、GridView、RecyclerView加载更多的同步平滑滚动.
  • 支持手势:同步Fling(刷新视图仍可见的情况下,会先回滚隐藏刷新视图,而后向下传递Fling手势).
  • 支持作为可拉伸内部视图布局使用(类小米设置页效果).
  • 丰富的回调接口和调试信息,可利用现有API实现丰富的效果.

引入

添加如下依赖到你的 build.gradle 文件:

dependencies {
    implementation 'com.github.dkzwm:srl-core:1.7.2.4'
    implementation 'com.github.dkzwm:srl-ext-classics:1.7.2.4'
    implementation 'com.github.dkzwm:srl-ext-material:1.7.2.4'
    implementation 'com.github.dkzwm:srl-ext-dynamic-rebound:1.7.2.4'
    implementation 'com.github.dkzwm:srl-ext-horizontal:1.7.2.4'
    implementation 'com.github.dkzwm:srl-ext-two-level:1.7.2.4'
    implementation 'com.github.dkzwm:srl-ext-util:1.7.2.4'
}

演示程序

下载 Demo.apk

更新日志

老版本升级务必查看

更新日志

快照

嵌套滑动 二级刷新

横向刷新 拉伸收缩效果

QQ红包活动 浏览器内核下拉展示

使用

在Xml中配置

<?xml version="1.0" encoding="utf-8"?>
<me.dkzwm.widget.srl.SmoothRefreshLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:app="http://schemas.android.com/apk/res-auto"
	android:id="@+id/refreshLayout"
	android:layout_width="match_parent"
	android:layout_height="match_parent">
	<TextView
		android:layout_width="match_parent"
		android:layout_height="match_parent"/>
</me.dkzwm.widget.srl.SmoothRefreshLayout>

Java代码配置

SmoothRefreshLayout refreshLayout = (SmoothRefreshLayout)findViewById(R.id.smoothRefreshLayout);
refreshLayout.setHeaderView(new ClassicHeader(this));
refreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {
	@Override
	public void onRefreshing() {
		mHandler.postDelayed(new Runnable() {
			@Override
			public void run() {
				refreshLayout.refreshComplete();
			}
		}, 4000);
	}
});

自定义刷新视图

接口定义
public interface IRefreshView <T extends IIndicator> {    

    byte TYPE_HEADER = 0;
    byte TYPE_FOOTER = 1;

    byte STYLE_DEFAULT = 0;
    byte STYLE_SCALE = 1;
    byte STYLE_PIN = 2;
    byte STYLE_FOLLOW_SCALE = 3;
    byte STYLE_FOLLOW_PIN = 4;
    byte STYLE_FOLLOW_CENTER = 5;

    /**
     * 返回是头部视图还是尾部视图;
     */
    int getType();

    /**
     * 一般情况都是View实现本接口,所以返回this;
     */
    View getView();

    /**
     * 获取视图样式,自1.4.8版本后支持6种样式,STYLE_DEFAULT、STYLE_SCALE、STYLE_PIN、STYLE_FOLLOW_SCALE、STYLE_FOLLOW_PIN、STYLE_FOLLOW_CENTER;
     */
    int getStyle();

    /**
     * 获取视图的自定义高度,当视图样式为STYLE_SCALE和STYLE_FOLLOW_SCALE时,必须返回一个确切且大于0的值,使用横向刷新库时,该属性实际应该返回的是视图的宽度;
     * 自1.6.1版本开始,如果想要当前视图铺满布局即MATCH_PARENT,那么支持返回ViewGroup.LayoutParams.MATCH_PARENT对应的值即`-1`;
     */
    int getCustomHeight();

    /**
     * 手指离开屏幕;
     */
    void onFingerUp(SmoothRefreshLayout layout, T indicator);

    /**
     * 重置视图;
     */
    void onReset(SmoothRefreshLayout layout);

    /**
     * 重新配置视图,准备刷新;
     */
    void onRefreshPrepare(SmoothRefreshLayout layout);

    /**
     * 开始刷新;
     */
    void onRefreshBegin(SmoothRefreshLayout layout, T indicator);

    /**
     * 刷新完成;
     */
    void onRefreshComplete(SmoothRefreshLayout layout,boolean isSuccessful);

    /**
     * 当头部或者尾部视图发生位置变化;
     */
    void onRefreshPositionChanged(SmoothRefreshLayout layout, byte status, T indicator);

    /**
     * 当头部或者尾部视图仍然处于处理事务中,这时候移动其他刷新视图则会调用该方法;
     * 在1.4.6版本新加入;
     */
    void onPureScrollPositionChanged(SmoothRefreshLayout layout, byte status, T indicator);
}
添加自定义刷新视图
  • 全局静态代码构造
        SmoothRefreshLayout.setDefaultCreator(new IRefreshViewCreator() {
            @Override
            public IRefreshView<IIndicator> createHeader(SmoothRefreshLayout layout) {
                ClassicHeader header = new ClassicHeader(layout.getContext());
                return header;
            }

            @Override
            public IRefreshView<IIndicator> createFooter(SmoothRefreshLayout layout) {
                ClassicFooter footer = new ClassicFooter(layout.getContext());
                return footer;
            }
        });
  • 动态代码添加
        ClassicHeader header = new ClassicHeader(mRefreshLayout.getContext());
        mRefreshLayout.setHeaderView(header);
        ClassicFooter footer = new ClassicFooter(mRefreshLayout.getContext());
        mRefreshLayout.setFooterView(footer);
  • 请直接写入Xml文件,SmoothRefreshLayout会根据添加的View是否是实现了IRefreshView接口进行判断

实现类QQ下拉阻尼效果

       mRefreshLayout.setIndicatorOffsetCalculator(new IIndicator.IOffsetCalculator() {
           @Override
           public float calculate(@IIndicator.MovingStatus int status, int currentPos, float offset) {
               if (status == IIndicator.MOVING_HEADER) {
                   if (offset < 0) {
                       //如果希望拖动缩回时类似QQ一样没有阻尼效果,阻尼效果只存在于下拉则可以在此返回offset
                       //如果希望拖动缩回时类似QQ一样有阻尼效果,那么请注释掉这个判断语句
                       return offset;
                   }
                   return (float) Math.pow(Math.pow(currentPos / 2, 1.28d) + offset, 1 / 1.28d) * 2 - currentPos;
               } else if (status == IIndicator.MOVING_FOOTER) {
                   if (offset > 0) {
                       //如果希望拖动缩回时类似QQ一样没有阻尼效果,阻尼效果只存在于上拉则可以在此返回offset
                       //如果希望拖动缩回时类似QQ一样有阻尼效果,那么请注释掉这个判断语句
                       return offset;
                   }
                   return -((float) Math.pow(Math.pow(currentPos / 2, 1.28d) - offset, 1 / 1.28d) * 2 - currentPos);
               } else {
                   if (offset > 0) {
                       return (float) Math.pow(offset, 1 / 1.28d) * 2;
                   } else if (offset < 0) {
                       return -(float) Math.pow(-offset, 1 / 1.28d) * 2;
                   } else {
                       return offset;
                   }
               }
           }
       });

Xml属性

SmoothRefreshLayout 自身配置
名称类型描述
sr_contentreference指定内容视图的资源ID
sr_resistancefloat移动刷新视图时候的移动阻尼(默认:1.65f)
sr_resistanceOfFooterfloat移动Footer视图时候的移动阻尼(默认:1.65f)
sr_resistanceOfHeaderfloat移动Header视图时候的移动阻尼(默认:1.65f)
sr_ratioToRefreshfloat触发刷新时位置占刷新视图的高度比(默认:1f)
sr_ratioOfHeaderToRefreshfloat触发刷新时位置占Header视图的高度比(默认:1f)
sr_ratioOfFooterToRefreshfloat触发加载更多时位置占Footer视图的高度比(默认:1f)
sr_ratioToKeepfloat刷新中保持视图位置占刷新视图的高度比(默认:1f),该属性的值必须小于等于触发刷新高度比才会有效果
sr_ratioToKeepHeaderfloat刷新中保持视图位置占Header视图的高度比(默认:1f),该属性的值必须小于等于触发刷新高度比才会有效果
sr_ratioToKeepFooterfloat刷新中保持视图位置占Footer视图的高度比(默认:1f),该属性的值必须小于等于触发刷新高度比才会有效果
sr_maxMoveRatiofloat最大移动距离占刷新视图的高度比(默认:0f,表示不会触发)
sr_maxMoveRatioOfHeaderfloat最大移动距离占Header视图的高度比(默认:0f,表示不会触发)
sr_maxMoveRatioOfFooterfloat最大移动距离占Footer视图的高度比(默认:0f,表示不会触发)
sr_closeDurationinteger指定收缩刷新视图到起始位置的时长(默认:350)
sr_closeHeaderDurationinteger指定收缩Header视图到起始位置的时长(默认:350)
sr_closeFooterDurationinteger指定收缩Footer视图到起始位置的时长(默认:350)
sr_backToKeepDurationinteger设置回滚到保持刷新视图位置的时间(默认:200)
sr_backToKeepHeaderDurationinteger设置回滚到保持Header视图位置的时间(默认:200)
sr_backToKeepFooterDurationinteger设置回滚到保持Footer视图位置的时间(默认:200)
sr_enablePinContentboolean固定内容视图(默认:false)
sr_enableKeepboolean刷新中保持视图停留在所设置的应该停留的位置(默认:true)
sr_enablePullToRefreshboolean拉动刷新,下拉或者上拉到触发刷新位置即立即触发刷新(默认:false)
sr_enableOverScrollboolean越界回弹(默认:true)
sr_enableRefreshboolean设置是否启用下拉刷新(默认:ture)
sr_enableLoadMoreboolean设置是否启用加载更多(默认:false)
sr_modeenum模式设置(默认:MODE_DEFAULT为刷新控件模式)
sr_stickyHeaderreference指定黏贴头部的资源ID
sr_stickyFooterreference指定黏贴尾部的资源ID
TwoLevelSmoothRefreshLayout 自身配置
名称类型描述
sr_enableTwoLevelRefreshboolean设置是否启用二级刷新(默认:true)
sr_backToKeep2Durationboolean设置回滚到保持二级刷新头部处于二级刷新过程中的时长(默认:500)
sr_closeHeader2Durationboolean设置关闭二级刷新头部的时长(默认:500)
SmoothRefreshLayout包裹内部其他View支持配置
名称类型描述
layout_gravityflag指定其它被包裹视图的对齐属性(非 targetView、非refreshView)

SmoothRefreshLayout java属性设置方法

名称参数描述
setHeaderViewIRefreshView配置头部视图
setFooterViewIRefreshView配置尾部视图
setContentViewView配置内容视图
setModeint配置当前模式
setLayoutManagerLayoutManager配置自定义布局管理器
setDisableWhenAnotherDirectionMoveboolean内部视图含有其他方向滑动视图时需设置该属性为ture(默认:false)
setMaxOverScrollDurationint设置越界回弹动画最长时间(默认:350)
setMinOverScrollDurationint设置越界回弹动画最短时间(默认:100)
setResistancefloat移动刷新视图时候的移动阻尼(默认:1.65f)
setResistanceOfFooterfloat移动Footer视图时候的移动阻尼(默认:1.65f)
setResistanceOfHeaderfloat移动Header视图时候的移动阻尼(默认:1.65f)
setRatioToRefreshfloat触发刷新时位置占刷新视图的高度比(默认:1.1f)
setRatioOfHeaderToRefreshfloat触发刷新时位置占Header视图的高度比(默认:1.1f)
setRatioOfFooterToRefreshfloat触发加载更多时位置占Footer视图的高度比(默认:1.1f)
setRatioToKeepfloat刷新中保持视图位置占刷新视图的高度比(默认:1f),该属性的值必须小于等于触发刷新高度比才会有效果
setRatioToKeepHeaderfloat刷新中保持视图位置占Header视图的高度比(默认:1f),该属性的值必须小于等于触发刷新高度比才会有效果
setRatioToKeepFooterfloat刷新中保持视图位置占Footer视图的高度比(默认:1f),该属性的值必须小于等于触发刷新高度比才会有效果
setMaxMoveRatiofloat最大移动距离占刷新视图的高度比(默认:0f,表示不会触发)
setMaxMoveRatioOfHeaderfloat最大移动距离占Header视图的高度比(默认:0f,表示不会触发)
setMaxMoveRatioOfFooterfloat最大移动距离占Footer视图的高度比(默认:0f,表示不会触发)
setDurationToCloseint指定收缩刷新视图到起始位置的时长(默认:350)
setDurationToCloseHeaderint指定收缩Header视图到起始位置的时长(默认:350)
setDurationToCloseFooterint指定收缩Footer视图到起始位置的时长(默认:350)
setDurationOfBackToKeepinteger设置回滚到保持刷新视图位置的时间(默认:200)
setDurationOfBackToKeepHeaderinteger设置回滚到保持Header视图位置的时间(默认:200)
setDurationOfBackToKeepFooterinteger设置回滚到保持Footer视图位置的时间(默认:200)
setEnablePinContentViewboolean固定内容视图(默认:false)
setEnablePullToRefreshboolean拉动刷新,下拉或者上拉到触发刷新位置即立即触发刷新(默认:false)
setEnableOverScrollboolean越界回弹(默认:true)
setEnableInterceptEventWhileLoadingboolean刷新中拦截不响应触摸操作(默认:false)
setEnableHeaderDrawerStylebooleanHeader抽屉样式,即Header视图在内容视图下面(默认:false)
setEnableFooterDrawerStylebooleanFooter抽屉样式,即Footer视图在内容视图下面(默认:false)
setDisablePerformRefreshboolean关闭触发Header刷新(默认:false)
setDisablePerformLoadMoreboolean关闭触发Footer刷新(默认:false)
setEnableNoMoreDataboolean设置Footer没有更多数据,该选项设置true时在Frame层等同setDisablePerformLoadMore设置为true,只是自定义视图可以根据该标志位改变视图样式,ClassicFooter默认实现了对该属性的支持(默认:false)
setEnableNoMoreDataAndNoSpringBackboolean设置Footer没有更多数据且不再回弹
setDisableRefreshboolean禁用Header刷新(默认:false)
setDisableLoadMoreboolean禁用Footer刷新(默认:false)
setEnableKeepRefreshViewboolean刷新中保持视图停留在所设置的应该停留的位置(默认:true)
setEnableAutoRefreshboolean到顶部自动刷新(默认:false)
setEnableAutoLoadMoreboolean到底部自动加载(默认:false)
setEnablePinRefreshViewWhileLoadingboolean固定刷新视图在所设置的应该停留的位置,并且不响应移动,即Material样式(默认:false),设置开启会同时开启setEnablePinContentView和setEnableKeepRefreshView2个选项
setSpringInterpolatorInterpolator设置主动弹出时的滚动插值器
setSpringBackInterpolatorInterpolator设置释放时的滚动插值器
setEnableCompatSyncScrollboolean设置是否开启回滚时的同步滚动(默认:true)
setDisableLoadMoreWhenContentNotFullboolean设置当内容视图未满屏时关闭加载更多
setStickyHeaderResIdint设置黏贴头部视图的资源ID
setStickyFooterResIdint设置黏贴头部视图的资源ID
setEnableOldTouchHandlingboolean设置启用老版本的触摸事件处理逻辑
setScrollTargetViewView设置判断是否滚到到边界对应的视图,例如在SmoothRefreshLayout中有一个CoordinatorLayout,CoordinatorLayout中有AppbarLayout、RecyclerView等,加载更多时希望被移动的视图为RecyclerView而不是CoordinatorLayout,那么设置RecyclerView为TargetView即可

SmoothRefreshLayout 回调

名称参数描述
setOnRefreshListenerT extends OnRefreshListener设置刷新事件监听回调
addLifecycleObserverILifecycleObserver添加生命周期监听
addOnStatusChangedListeneraddOnStatusChangedListener设置内部状态改变回调
addOnUIPositionChangedListenerOnUIPositionChangedListener添加视图位置变化的监听回调
setOnSyncScrollCallbackOnSyncScrollCallback设置完成刷新后进行平滑滚动的回调
setOnPerformAutoLoadMoreCallBackOnPerformAutoLoadMoreCallBack设置触发自动加载更多的条件回调,如果回调的canAutoLoadMore()方法返回true则会立即触发加载更多
setOnPerformAutoRefreshCallBackOnPerformAutoRefreshCallBack设置触发自动刷新的条件回调,如果回调的canAutoRefresh()方法返回true则会立即触发刷新
setOnHeaderEdgeDetectCallBackOnHeaderEdgeDetectCallBack设置检查内容视图是否在顶部的重载回调(SmoothRefreshLayout内部isNotYetInEdgeCannotMoveHeader()方法)
setOnFooterEdgeDetectCallBackOnFooterEdgeDetectCallBack设置检查内容视图是否在底部的重载回调(SmoothRefreshLayout内部isNotYetInEdgeCannotMoveFooter()方法)
setOnHookHeaderRefreshCompleteCallbackOnHookUIRefreshCompleteCallBack设置Header刷新完成的Hook回调,可实现延迟完成刷新
setOnHookFooterRefreshCompleteCallbackOnHookUIRefreshCompleteCallBack设置Footer刷新完成的Hook回调,可实现延迟完成刷新

SmoothRefreshLayout 其它

名称参数描述
setDefaultCreator(静态方法)IRefreshViewCreator设置刷新视图创建者,如果没有特殊指定刷新视图且设置的模式需要刷新视图则会调用创建者构建刷新视图
refreshComplete无参刷新完成,且设置最后一次刷新状态为成功
refreshCompleteboolean刷新完成,参数:设置最后一次刷新是否刷新成功
refreshCompleteboolean,long刷新完成,参数1:设置最后一次刷新是否刷新成功,参数2:设置延迟重置刷新状态的时间(会先触发刷新视图的刷新完成回调,但在延迟的时间内库实际上状态仍是刷新状态)
refreshCompletelong刷新完成,且设置最后一次刷新状态为成功,参数:设置延迟重置刷新状态的时间(会先触发刷新视图的刷新完成回调,但在延迟的时间内库实际上状态仍是刷新状态)
setLoadingMinTimelong设置开始刷新到结束刷新的最小时间差(默认:500),参数:时间差
autoRefresh无参自动触发Header刷新,立即触发刷新事件并滚动到触发Header刷新位置
autoRefreshboolean自动触发Header刷新,参数:是否立即触发刷新事件,会滚动到触发Header刷新位置
autoRefreshboolean,boolean自动触发Header刷新,参数1:是否立即触发刷新事件,参数2:是否滚动到触发Header刷新位置
forceRefresh无参强制触发Footer刷新,该方法不会触发滚动
autoLoadMore无参自动触发Footer刷新,立即触发刷新事件并滚动到触发Footer刷新位置
autoLoadMoreboolean自动触发Footer刷新,参数:是否立即触发刷新事件,会滚动到触发Footer刷新位置
autoLoadMoreboolean,boolean自动触发Footer刷新,参数1:是否立即触发刷新事件,参数2:是否滚动到触发Footer刷新位置
forceLoadMore无参强制触发Footer刷新,该方法不会触发滚动

TwoLevelSmoothRefreshLayout java属性设置方法

名称参数描述
setRatioOfHeaderToHintTwoLevelfloat设置触发二级刷新提示时的位置占Header视图的高度比
setRatioOfHeaderToTwoLevelfloat设置触发二级刷新时的位置占Header视图的高度比
setRatioToKeepTwoLevelHeaderfloat二级刷新中保持视图位置占Header视图的高度比(默认:1f)
setDisableTwoLevelRefreshboolean设置是否关闭二级刷新(默认:false)
setDurationOfBackToKeepTwoLevelint设置回滚到保持二级刷新Header视图位置的时间(默认:500)
setDurationToCloseTwoLevelint设置二级刷新Header刷新完成回滚到起始位置的时间(默认:500)

TwoLevelSmoothRefreshLayout 其它

名称参数描述
autoTwoLevelRefreshHint无参自动触发二级刷新提示并滚动到触发提示位置后回滚回起始位置
autoTwoLevelRefreshHintint自动触发二级刷新提示并滚动到触发提示位置后停留指定时长,参数:停留多长时间
autoTwoLevelRefreshHintboolean自动触发二级刷新提示是否滚动到触发提示位置后回滚回起始位置,参数:是否滚到到触发位置
autoTwoLevelRefreshHintboolean,int自动触发二级刷新提示,参数1:是否滚动到触发位置,参数2:停留多长时间
autoTwoLevelRefreshHintboolean,int,boolean自动触发二级刷新提示,参数1:是否滚动到触发位置,参数2:停留多长时间,参数3:是否可以被触摸打断,即触发提示动作过程中拦截触摸事件,直到回滚到起始位置并重置为默认状态

Thanks

License

MIT License

Copyright (c) 2017 dkzwm
Copyright (c) 2015 liaohuqiu.net

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.