SmartRefreshLayout的目标是打造一个强大,稳定,成熟的下拉刷新框架,并集成各种的炫酷、多样、实用、美观的Header和Footer。 正如名字所说,SmartRefreshLayout是一个“聪明”或者“智能”的下拉刷新布局,由于它的“智能”,它不只是支持所有的View,还支持多层嵌套的视图结构。 它继承自ViewGroup 而不是FrameLayout或LinearLayout,提高了性能。 也吸取了现在流行的各种刷新布局的优点,包括谷歌官方的 SwipeRefreshLayout, 其他第三方的 Ultra-Pull-To-Refresh、TwinklingRefreshLayout 。 还集成了各种炫酷的 Header 和 Footer。
项目地址:https://github.com/scwang90/SmartRefreshLayout
依赖
V7包版本
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-28'
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-alpha-28'//没有使用特殊Header,可以不加这行
implementation 'com.android.support:appcompat-v7:25.3.1'//版本 23以上(必须)
androidx 版本
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-andx-11'
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-andx-11'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
使用
SmartRefreshLayout中如果有多个控件,第一个控件会变成Header,第二个控件作为主体,第三个控件则是Footer
<SmartRefreshLayout>
<ClassicsHeader/>
<LinearLayout/>
<ClassicsFooter/>
</SmartRefreshLayout>
eg:实例:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.scwang.smartrefresh.header.DeliveryHeader
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list_text"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.scwang.smartrefresh.layout.footer.ClassicsFooter
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srlClassicsSpinnerStyle="Translate" />
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
</LinearLayout>
设置刷新和加载更多的事件监听
设置刷新和加载更多事件监听
public SmartRefreshLayout setOnRefreshListener(OnRefreshListener listener);
public SmartRefreshLayout setOnLoadMoreListener(OnLoadMoreListener listener)
//完成加载更多或者刷新
public SmartRefreshLayout finishLoadMore(boolean success);
public SmartRefreshLayout finishRefresh()
最终效果图:
自定义Header和Footer,参考博客: https://www.jianshu.com/p/df6964cd745c
关于更多的基本使用,参考博客:https://www.jianshu.com/p/29e315ff44a6