小编Sim*_*oid的帖子

带有 ViewPager2 的 BottomSheetBehavior 无法通过嵌套的 RecyclerView 滚动向下滚动

我有一个类似于BottomSheetBehavior的视图,这个视图里面有ViewPager2。每个 ViewPager2 的页面都是一个垂直的 RecyclerView。问题是当当前垂直 RecyclerView(它是 ViewPager 的页面)不能再垂直滚动时,BottomSheet 不会向下滚动。当我只有一个垂直 RecyclerView 而不是 ViePager 时,一切正常。

临时解决方案是用 NestedScrollView 包装 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"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/core"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#C7C7C7"
        tools:context=".MainActivity">

        <LinearLayout
            android:id="@+id/bottom_sheet"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FFFFFF"
            android:elevation="8dp"
            android:orientation="vertical"
            app:behavior_hideable="true"
            app:behavior_peekHeight="300dp"
            app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

            <com.google.android.material.tabs.TabLayout
                android:id="@+id/tab_layout"
                android:layout_width="wrap_content"
                android:layout_height="24dp"
                android:layout_gravity="center_horizontal"
                app:tabGravity="center"
                app:tabMode="scrollable" />

            <androidx.viewpager2.widget.ViewPager2
                android:id="@+id/view_pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </LinearLayout>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

[这是它的外观(对 gif 质量感到抱歉)]

在此处输入图片说明

android bottom-sheet android-viewpager2

10
推荐指数
1
解决办法
1475
查看次数

标签 统计

android ×1

android-viewpager2 ×1

bottom-sheet ×1