一个高效、稳定、强大的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中配置



    

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才能达到最优效果

你可能感兴趣的:(一个高效、稳定、强大的Android刷新库SmoothRefreshLayout)