1.导入依赖
implementation 'com.lcodecorex:tkrefreshlayout:1.0.7'
2.嵌套ScollView
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat 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"
tools:context=".MainActivity">
<com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout
android:id="@+id/scover_personal_information"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
//页面内容
//页面内容
//页面内容
//页面内容
//页面内容
</LinearLayout>
</ScrollView>
</com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
3.初始化控件设置上下拉效果
TwinklingRefreshLayout twinklingRefreshLayout = findViewById(R.id.scover_personal_information); //找到控件
twinklingRefreshLayout.setPureScrollModeOn(); //设置回弹效果
总结
这里面同时可以设置下拉刷新和上拉加载等,调用不同TwinklingRefreshLayout控件的方法就可以。