Coder Social home page Coder Social logo

simplerefreshlayout's Introduction

SimpleRefreshLayout

  • 1.支持下拉刷新,上拉加载以及无更多;
  • 2.支持coordinatorLayout,适配继承NestedScrollParent的父组件
  • 3.支持listview等其他组件
  • 4.支持加载布局自定义;

demo效果

recyclerView.gif coordinatorlayout.gif

使用

gradle依赖

compile 'com.dengzq.widget:simplerefreshlayout:0.8.0'

1.布局配置

1.在xml中作为一个viewgroup使用。 注:子布局只能有一个
eg:

<com.dengzq.simplerefreshlayout.SimpleRefreshLayout
        android:id="@+id/simple_refresh"
        android:background="#F5F8F9"
        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.dengzq.simplerefreshlayout.SimpleRefreshLayout>

2.相关方法

  1. 下拉刷新、上拉加载监听
mSimpleRefreshLayout.setOnSimpleRefreshListener(new SimpleRefreshLayout.OnSimpleRefreshListener() {
            @Override
            public void onRefresh() {
                //下拉刷新完成
                mSimpleRefreshLayout.onRefreshComplete();
            }

            @Override
            public void onLoadMore() {
               //上拉加载完成
               mSimpleRefreshLayout.onLoadMoreComplete();
            }
        });
  1. 是否开启刷新、上拉
mSimpleRefreshLayout.setPullUpEnable(true);
mSimpleRefreshLayout.setPullDownEnable(true);
  1. 自定义刷新、加载、无更多布局
  • 自定义刷新布局请实现IHeaderWrapper接口

mSimpleRefreshLayout.setHeaderView( your view here);

public interface IHeaderWrapper {

    /**
     * 获取刷新布局
     * @return
     */
    View getHeaderView();

    /**
     * 下拉中
     */
    void pullDown();

    /**
     * 下拉可刷新
     */
    void pullDownReleasable();

    /**
     * 下拉刷新中
     */
    void pullDownRelease();
}
  • 自定义上拉加载布局请实现IFooterWrapper接口

mSimpleRefreshLayout.setFooterView(your view here);

public interface IFooterWrapper {

    /**
     * 获取加载更多布局
     *
     * @return
     */
    View getFooterView();

    /**
     * 上拉中
     */
    void pullUp();

    /**
     * 上拉可释放
     */
    void pullUpReleasable();

    /**
     * 上拉已释放
     */
    void pullUpRelease();
}
  • 自定义无更多布局请实现IBottomWrapper接口

mSimpleRefreshLayout.setBottomView(your view here);

public interface IBottomWrapper {

    /**
     * 获取无更多布局
     *
     * @return
     */
    View getBottomView();

    /**
     * 显示无更多布局
     */
    void showBottom();
}
  1. 显示无更多布局

显示无更多布局,需要先配置:

mSimpleRefreshLayout.setPullUpEnable(true), mSimpleRefreshLayout.setBottomView( your view here );

在服务器返回数据小于你所设置的分页数时,可认为无更多数据。此时, mSimpleRefreshLayout.showNoMore(true);即可显示无更多底部。

  1. 其他属性

1> 三种布局在simpleRefreshLayout中的高度(一般不需要配置)

mSimpleRefreshLayout.setChildHeaderHeight(int val);
mSimpleRefreshLayout.setChildFooterHeight(int val);
mSimpleRefreshLayout.setChildBottomHeight(int val);

2> 下拉刷新,上拉加载事件的有效高度(根据个人刷新布局高度处理)

默认下拉有效的高度为80dp,上拉有效的高度为45dp

mSimpleRefreshLayout.setEffectivePullDownRange(int val);
mSimpleRefreshLayout.setEffectivePullDownRange(int val);

版本更新

  • v0.8.0:
    bug fix;

  • v0.6.0:
    增加对coordinatorLayout的适配;
    修复部分已知问题;

  • v0.5.0:
    初始提交;

特别感谢

TwinklingRefreshLayout

CanRefresh

SmartAndroidWidgets

关于NestedScroll

我的博客

如果你喜欢本项目,请点个✨哦~

simplerefreshlayout's People

Contributors

dengzq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

simplerefreshlayout's Issues

上拉或下拉可能连续触发

很不错,但是有一点问题。例如下拉时,我请求数据花了大概几秒,在这几秒上拉动画期间,如果我再连续下滑,就会触发多次刷新事件。上拉同理,请问能否在一次动画期间屏蔽其他上拉下拉操作呢。

上拉加载

上拉加载mFooterWrapper一直显示,调用onLoadMoreComplete无效

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.