我将 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/