我的观点类似于 BottomSheetBehavior这个 View 有 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>
[这是它的外观(对于 gif 质量抱歉)]
最佳答案
我已经为这种情况找到了解决方案,我设置了 isNestedScrollingEnabled = false
用于内部 RecyclerView 以便 BottomSheetBehavior 找到另一个 ScrollView
viewPager.children.find { it is RecyclerView }?.let {
(it as RecyclerView).isNestedScrollingEnabled = false
}
关于android - 嵌套的 RecyclerView 滚动无法向下滚动 ViewPager2 的 BottomSheetBehavior,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61465262/