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