天天看点

SmartRefreshLayout 上拉加载下拉刷新依赖XML 事例JAVA 方法Header 和 Footer 的样式参考地址

SmartRefreshLayout

  • 依赖
  • XML 事例
  • JAVA 方法
  • Header 和 Footer 的样式
  • 参考地址

依赖

implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-28'
    implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-alpha-28'//没有使用特殊Header,可以不加这行
           

版本更新了,依赖变更:

implementation 'com.scwang.smart:refresh-layout-kernel:2.0.1'
    implementation 'com.scwang.smart:refresh-header-classics:2.0.1'
    implementation 'com.scwang.smart:refresh-footer-classics:2.0.1'
           

XML 事例

<com.scwang.smartrefresh.layout.SmartRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/smart_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".business.vehicle.ui.notice.NoticeFragment">

        <com.....widget.recycler.SkCustom2ClassicsHeader
            android:layout_width="match_parent"
            android:layout_height="150dp" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <include layout="@layout/layout_empty" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="5dp" />

        </RelativeLayout>

        <com.scwang.smartrefresh.layout.footer.ClassicsFooter
            android:layout_width="match_parent"
            android:layout_height="80dp" />

    </com.scwang.smartrefresh.layout.SmartRefreshLayout>
           

JAVA 方法

//刷新和加载
        smartRefreshLayout.setOnRefreshListener(refreshLayout -> refresh());
        smartRefreshLayout.setOnLoadMoreListener(refreshLayout -> loadMore());

	//支持刷新和加载
        smartRefreshLayout.setEnableRefresh(state);
        smartRefreshLayout.setEnableLoadMore(state);
    
	//刷新完成和加载完成
        smartRefreshLayout.finishRefresh();
        smartRefreshLayout.finishLoadMore();

	//自动刷新
        smartRefreshLayout.autoRefresh();
           

其中设置Header和Footer的方式,我们使用的是布局设置,除此之外还有全局设置和代码设置。

Header 和 Footer 的样式

refresh-layout-kernel 核心必须依赖

refresh-header-classics 经典刷新头

refresh-header-radar 雷达刷新头

refresh-header-falsify 虚拟刷新头

refresh-header-material 谷歌刷新头

refresh-header-two-level 二级刷新头

refresh-footer-ball 球脉冲加载

refresh-footer-classics 经典加载

博主效果样式地址:https://github.com/scwang90/SmartRefreshLayout

参考地址

源码

地址:https://github.com/scwang90/SmartRefreshLayout

属性地址:https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_property.md

博客地址:Android智能下拉刷新框架-SmartRefreshLayout