<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.realm.RealmDemo">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/swipe_refresh_layout">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/recycle_view"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
使用比较简单 这里就模拟了一下加载效果 下拉触发加载显示动画此时isRefreshing=true 加载数据后需要修改为false 隐藏动画
swipe_refresh_layout.isRefreshing = false
swipe_refresh_layout.setOnRefreshListener {
Handler().postDelayed({
swipe_refresh_layout.isRefreshing = false
},2000)
}