android - 当 Bottom Sheet android中的recyclerview时防止用户在 Bottom Sheet 中拖动

标签 android android-recyclerview bottom-sheet

我将 relativelayout 作为 bottomsheet 行为。在 relativelayout 中,我有 imageview,下面是 recyclerview。现在我想防止用户在 recyclerview 中向下滑动时拖动。我已经尝试在 onStateChanged 方法中设置模式扩展,但它似乎不起作用,因为我有 recyclerview。

mBottomSheetBehavior = BottomSheetBehavior.from(bottomsheetLayout);
    mBottomSheetBehavior.setPeekHeight(0);
mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {

           if (newState == BottomSheetBehavior.STATE_DRAGGING) {
                mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
            }
        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {

        }

    });

我的 xml 文件是:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:visibility="visible"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
    android:id="@+id/dragView1">




    <ImageView
        android:layout_width="32dp"
        android:src="@drawable/iv_close"
        android:padding="@dimen/margin_5"
        android:layout_marginTop="@dimen/margin_5"
        android:id="@+id/ivItemsClose"
        android:layout_marginRight="@dimen/margin_5"
        android:clickable="true"
        android:layout_alignParentRight="true"
        android:layout_height="32dp" />

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:id="@+id/rcBoutique"
        android:overScrollMode="never"
        android:layout_height="wrap_content"/>
</Relativelayout>

如何防止拖动使 bottomsheet 不折叠?

最佳答案

我也遇到了这个问题,然后我通过在 RecyclerView 中使用 android:nestedScrollingEnabled="false" 解决了它,这一行可以禁用嵌套滚动行为。

BottomSheet 和 Recyclerview 都有滚动行为,这就是生成此问题的原因。

<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:id="@+id/rcBoutique"
    android:overScrollMode="never"
    android:layout_height="wrap_content"
    android:nestedScrollingEnabled="false"/>

关于android - 当 Bottom Sheet android中的recyclerview时防止用户在 Bottom Sheet 中拖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45732369/

相关文章:

android - 将 JSON 响应的值存储在 arraylist 中,然后根据 JSONObject 输出过滤它们

Android - 如何在 View 上绘制

android - onClick 和 onLongClick 似乎是并行触发的

android - ScrollView里面的RecyclerView,有些item没有显示

android - Bottom Sheet 和FAB边距

java - Android - 从 Fragment 中设置 BottomSheet 中 FAB 按钮的可见性

android - ListView 列表选择器不工作

java - 如何将 cursorLoader 转换为 Loader<Object>

android - scrollBy 在嵌套的 recyclerview 中不能正常工作

android - Bottom Sheet 错误 : The view is not a child of CoordinatorLayout