开发者社区> 问答> 正文

当我在BottomSheet中滚动浏览RecyclerView时,BottomSheet下的Recy

如标题所示,当我滚动浏览BottomSheet中的RecyclerView时,RecyclerView会滚动到BottomSheet下。仅滚动BottomSheet中的RecyclerView怎么办?

这是我的布局:


<androidx.coordinatorlayout.widget.CoordinatorLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android/white"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        app:elevation="0dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlways">

            <TextView
                android:id="@+id/titleTextView"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="32dp"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="32dp"
                android:layout_marginBottom="16dp"
                android:text="Title"
                android:textColor="@android:color/black"
                android:textSize="30sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"

                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/itemRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="90dp"
            android:fastScrollEnabled="true"
            android:overScrollMode="never"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </FrameLayout>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/bottomSheet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"

        app:behavior_hideable="false"
        app:behavior_peekHeight="88dp"

        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

        <View
            android:id="@+id/bottomSheetShadow"
            android:layout_width="match_parent"
            android:layout_height="4dp"
            android:background="@drawable/bottom_sheet_shadow"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/bottomSheetLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/bottomSheetShadow">

            <View
                android:id="@+id/bottomSheetSliderView"
                android:layout_width="24dp"
                android:layout_height="4dp"
                android:layout_marginTop="8dp"
                android:background="@drawable/bottom_sheet_slider"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/bottomSheetTitleTextView"
                android:layout_width="match_parent"
                android:layout_height="42dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="16dp"
                android:text="BottomSheetTitle"
                android:textColor="@android:color/black"
                android:textSize="30sp"
                app:layout_constraintEnd_toEndOf="parent"

                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/bottomSheetSliderView" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/navRecyclerView"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_marginTop="32dp"
                android:overScrollMode="never"
                app:elevation="0dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHeight_default="wrap"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/bottomSheetTitleTextView" />
        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

我已经尝试设置android:clickable="true"和设置android:focusable="true"BottomSheet布局,或者设置没有功能的OnClickListener。

展开
收起
Puppet 2020-01-06 15:35:03 525 0
1 条回答
写回答
取消 提交回答
  • 只需更改您的底部工作表协调器布局即可 CardView layout

    
    <androidx.coordinatorlayout.widget.CoordinatorLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android/white"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android">
    
        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            app:elevation="0dp">
    
            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="scroll|enterAlways">
    
                <TextView
                    android:id="@+id/titleTextView"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="32dp"
                    android:layout_marginTop="16dp"
                    android:layout_marginEnd="32dp"
                    android:layout_marginBottom="16dp"
                    android:text="Title"
                    android:textColor="@android:color/black"
                    android:textSize="30sp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
    
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />
    
            </androidx.constraintlayout.widget.ConstraintLayout>
        </com.google.android.material.appbar.AppBarLayout>
    
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
    
            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/itemRecyclerView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="90dp"
                android:fastScrollEnabled="true"
                android:overScrollMode="never"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
        </FrameLayout>
    
        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/bottomSheet"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
    
            app:behavior_hideable="false"
            app:behavior_peekHeight="88dp"
    
            app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
    
            <View
                android:id="@+id/bottomSheetShadow"
                android:layout_width="match_parent"
                android:layout_height="4dp"
                android:background="@drawable/bottom_sheet_shadow"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
    
            <androidx.cardview.widget.CardView  // here
                android:id="@+id/bottomSheetLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/bottomSheetShadow">
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
                <View
                    android:id="@+id/bottomSheetSliderView"
                    android:layout_width="24dp"
                    android:layout_height="4dp"
                    android:layout_marginTop="8dp"
                    android:background="@drawable/bottom_sheet_slider"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />
    
                <TextView
                    android:id="@+id/bottomSheetTitleTextView"
                    android:layout_width="match_parent"
                    android:layout_height="42dp"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginEnd="16dp"
                    android:text="BottomSheetTitle"
                    android:textColor="@android:color/black"
                    android:textSize="30sp"
                    app:layout_constraintEnd_toEndOf="parent"
    
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/bottomSheetSliderView" />
    
                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/navRecyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_marginTop="32dp"
                    android:overScrollMode="never"
                    app:elevation="0dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHeight_default="wrap"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/bottomSheetTitleTextView" />
    
              </RelativeLayout>
            </androidx.cardview.widget.CardView>
        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.coordinatorlayout.widget.CoordinatorLayout> 
    
    2020-01-06 15:35:35
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载