使用CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout+TabLayout+ViewPager,实现tab滑动吸顶效果简直完爆ScrollView实现的效果。
AppBarLayout + CollapsingToolbarLayout有几大有点:
1.无需处理ScrollView + ViewPager的滑动事件冲突
2. 无需关注ScrollView 和 RecyclerView滑动是否触底或者触顶
3. 实现起来超级简单,无需做其他优化,除非你有特殊需求。
废话不多数,直接上代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:fitsSystemWindows="true">
<!--


被折叠的 条评论
为什么被折叠?



