【问题标题】:Unable to scroll RecyclerView inside NestedScrollView inside BottomSheetBehavior无法在 BottomSheetBehavior 内的 NestedScrollView 内滚动 RecyclerView
【发布时间】:2019-05-20 10:16:55
【问题描述】:

问题是每当我尝试滚动RecyclerViewBottomSheet 滚动

主布局

<?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="@color/white"
    android:clickable="true"
    android:focusable="true">


    <include layout="@layout/layout_map_view" />

    <include layout="@layout/layout_bs_days_activities" />


</androidx.coordinatorlayout.widget.CoordinatorLayout>

layout_map_view.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:focusable="true">


    <com.google.android.gms.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


</LinearLayout>

layout_bs_days_activities.xml

<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/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/_8sdp"
        android:theme="@style/AppTheme.WhiteAccent">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:contentInsetStart="0dp"
            android:contentInsetLeft="0dp"
            android:contentInsetEnd="0dp"
            android:contentInsetRight="0dp"
            android:minHeight="?attr/actionBarSize"
            app:contentInsetEnd="0dp"
            app:contentInsetLeft="0dp"
            app:contentInsetRight="0dp"
            app:contentInsetStart="0dp">


            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rv_days"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/_8sdp"
                android:orientation="horizontal"
                app:layoutManager=".utils.customviews.LinearLayoutManagerWrapper"
                tools:listitem="@layout/item_day" />


        </androidx.appcompat.widget.Toolbar>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:id="@+id/nested_scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rv_activities"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </androidx.core.widget.NestedScrollView>


</androidx.coordinatorlayout.widget.CoordinatorLayout>

【问题讨论】:

  • 为什么在 MapView 下面使用 BottomSheet?使用底页的最佳方法是创建一个新的BottomSheetDialogFragment 并随时调用。查看this blog 或者您可以参考任何其他底页示例。

标签: android android-recyclerview android-nestedscrollview android-bottomsheetdialog


【解决方案1】:

尝试在 RecyclerView 中设置 focusableOnTouchMode=true

【讨论】:

    猜你喜欢
    • 2016-10-20
    • 1970-01-01
    • 2020-06-01
    • 2021-12-10
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多