kotlin 粘滞选项卡在回收机视图上方的布局

iswrvxsc  于 2022-11-25  发布在  Kotlin
关注(0)|答案(1)|浏览(116)

当你向下滚动时,带有横幅的水平RecyclerView会换行,TabLayout会粘在AppBar上。你们知道如何实现它吗?

goucqfw6

goucqfw61#

你可以像下面这样在CoordinatorLayout中使用TabLayout,并把所有你想折叠的视图放在CollapsingToolbarLayout中:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.constraintlayout.widget.ConstraintLayout
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/mainFilterLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/homeBg">

        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <include
                android:id="@+id/toolbarCollapse"
                layout="@layout/layout_collapsable"
                android:layout_width="match_parent"
                android:layout_height="@dimen/_126dp" />

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="@dimen/_8dp"
                android:animateLayoutChanges="true"
                android:background="@color/lightBase1"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

                <com.google.android.material.tabs.TabLayout
                    android:id="@+id/tabLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@color/lightBase1"
                    android:clipToPadding="false"
                    android:paddingStart="@dimen/_10dp"
                    android:paddingEnd="@dimen/_10dp"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior"
                    app:layout_collapseMode="pin"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:tabGravity="start"
                    app:tabIndicator="@drawable/ic_lineider_2022"
                    app:tabIndicatorColor="@color/lightBaseFill"
                    app:tabIndicatorHeight="@dimen/_2dp"
                    app:tabMode="fixed"
                    app:tabRippleColor="@color/transparent"
                    app:tabSelectedTextColor="@color/lightTextColor" />

                <androidx.recyclerview.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:id="@+id/recycler"
                    tools:listitem="@layout/index_inner_layout"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/tabLayout"/>

        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

相关问题