上效果图
device-2020-06-08-174856
有3种解决方法先大概说一下:
1.设置ScrollView的fillViewPort为true。然后给viewpager设置固定的高度值。(局限性很大,ScrollView不能跟着一起滑动了,只有viewpager能)。
2.网上还有一种方法,重写viewpager,但是会留下空白,不留空白的会发现很卡。(亲测)https://blog.csdn.net/qq_27400335/article/details/81116982
3.自己捣鼓的一套方法,既不留空白,也不会卡。只是转变了一下思路。先说一下,下面帖代码,这种方式也可以解决tablayout的吸顶。
这种方法去掉了ScrollView,然后转用了谷歌给我们提供的控件,
CoordinatorLayout
AppBarLayout
CollapsingToolbarLayout
通过这三个组合使用,然后再把自己的viewpager拿出来,像往常一样使用即可。既不会出现问题,也不难以理解,倒还可以增加一些动画效果。
<?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">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
>
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
这里面是设置自己的头部,根据自己的来进行设置
</LinearLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
这里是tabLayout。
<com.qmuiteam.qmui.widget.QMUITabSegment
android:id="@+id/tabLayout"
android:layout_marginTop="30dp"
android:background="@color/colorWhite"
android:layout_width="match_parent"
android:layout_height="40dp"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
,如有不懂欢迎底部留言
1780

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



