一个高效、稳定、强大的Android刷新库SmoothRefreshLayout

项目地址
https://github.com/dkzwm/SmoothRefreshLayout
特性:
理论上支持所有的视图,且可根据具体需求高效适配.
支持5种模式,NONE(做为FrameLayout使用)、REFRESH(头部刷新)、LOAD_MORE(底部刷新)、BOTH(头部刷新和底部刷新)、OVER_SCROLL(越界回弹).
支持嵌套滑动,完整实现了NestedScrollingChild,NestedScrollingParent 接口,玩转CoordinatorLayout.
直接继承自ViewGroup,拥有卓越的性能,支持类FameLayout的特性(Gravity、Margin).
支持自动刷新、自动上拉加载、到底自动加载更多(不推荐,建议使用Adapter实现).
支持越界回弹.
支持抽屉效果.
支持二级刷新事件(TwoLevelSmoothRefreshLayout).
支持ListView,RecyclerView加载更多的平滑滚动.
支持内容视图的Margin,PS:滚动中没有了Margin效果?SmoothRefreshLayout不存在这种问题.
丰富的回调接口和调试信息,可利用现有Api实现丰富的效果.

测试QQ浏览器样式

测试QQ活动样式

测试2级刷新

包含FrameLayout

包含TextView

包含ListView

包含GridView

包含RecyclerView

包含ViewPager

包含WebView

CoordinatorLayout

越界回弹模式

测试嵌套滑动

使用

Gradle

repositories {  
    ...
    maven { url 'https://jitpack.io' }  
}

dependencies {  
    compile 'com.github.dkzwm:SmoothRefreshLayout:1.3.2'
}

在Xml中配置

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

Java代码配置

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

自定义刷新视图
接口定义

public interface IRefreshView {
    byte TYPE_HEADER = 0;
    byte TYPE_FOOTER = 1;

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

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

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

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

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

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

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

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

}

添加自定义刷新视图
代码添加

setHeaderView(@NonNull IRefreshView header);
setFooterView(@NonNull IRefreshView footer);

Xml属性
SmoothRefreshLayout 自身配置

名称 类型 描述
sr_mode enum 模式设置(默认:none)
sr_content integer 指定内容视图的资源ID
sr_resistance float 刷新视图的移动阻尼(默认:1.65f)
sr_resistance_of_pull_up float Footer视图的移动阻尼(默认:1.65f)
sr_resistance_of_pull_down float Header视图的移动阻尼(默认:1.65f)
sr_ratio_of_refresh_height_to_refresh float 触发刷新时位置占刷新视图的高度比(默认:1.1f)
sr_ratio_of_header_height_to_refresh float 触发刷新时位置占Header视图的高度比(默认:1.1f)
sr_ratio_of_footer_height_to_refresh float 触发加载更多时位置占Footer视图的高度比(默认:1.1f)
sr_offset_ratio_to_keep_refresh_while_Loading float 刷新中保持视图位置占刷新视图的高度比(默认:1f),该属性的值必须小于等于触发刷新高度比才会有效果
sr_offset_ratio_to_keep_header_while_Loading float 刷新中保持视图位置占Header视图的高度比(默认:1f),该属性的值必须小于等于触发刷新高度比才会有效果
sr_offset_ratio_to_keep_footer_while_Loading float 刷新中保持视图位置占Footer视图的高度比(默认:1f),该属性的值必须小于等于触发刷新高度比才会有效果
sr_can_move_the_max_ratio_of_refresh_height float 最大移动距离占刷新视图的高度比(默认:0f,表示不会触发)
sr_can_move_the_max_ratio_of_header_height float 最大移动距离占Header视图的高度比(默认:0f,表示不会触发)
sr_can_move_the_max_ratio_of_footer_height float 最大移动距离占Footer视图的高度比(默认:0f,表示不会触发)
sr_duration_to_close_of_refresh integer 指定收缩刷新视图到起始位置的时长(默认:500)
sr_duration_to_close_of_header integer 指定收缩Header视图到起始位置的时长(默认:500)
sr_duration_to_close_of_footer integer 指定收缩Footer视图到起始位置的时长(默认:500)
sr_duration_of_back_to_refresh_height integer 收缩刷新视图到触发刷新位置的时长(默认:200)
sr_duration_of_back_to_header_height integer 收缩刷新视图到触发Header刷新位置的时长(默认:200)
sr_duration_of_back_to_footer_height integer 收缩刷新视图到触发Footer刷新位置的时长(默认:200)
sr_enable_pin_content boolean 固定内容视图(默认:false)
sr_enable_keep_refresh_view boolean 刷新中保持视图停留在所设置的应该停留的位置(默认:true)
sr_enable_pull_to_refresh boolean 拉动刷新,下拉或者上拉到触发刷新位置即立即触发刷新(默认:false)
sr_enable_over_scroll boolean 越界回弹(默认:true),使用者需要自己设置内容视图的 overScrollMode 为 never才能达到最优效果

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,314评论 19 139
  • 一、Android开发初体验 二、Android与MVC设计模式模型对象存储着应用的数据和业务逻辑。模型类通常用来...
    为梦想战斗阅读 4,554评论 0 3
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,044评论 25 709
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,655评论 2 45
  • 在十年之前,我身体素质较差,兼带有一些忧郁,喜欢看一些感伤的影剧,听一些忧郁的老歌,时不时会流泪;喜欢下雨天...
    扒哥阅读 2,394评论 0 0