我有一台带RecyclerView的BottomSheetDialogFragment。问题是,我想禁用BottomSheetDialogFragment的拖动关闭功能,只要RecyclerView没有向上滚动(目前我不能滚动我的RecyclerView,因为尝试总是关闭BottomSheetDialogFragment)。有什么办法可以做到这一点吗?
发布于 2019-02-20 08:40:38
通过这种方式可以解决BottomSheetDialog中的RecyclerView滚动问题。
来自:https://android.jlelse.eu/recyclerview-within-nestedscrollview-scrolling-issue-3180b5ad2542
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>发布于 2020-09-24 20:08:22
在您在onCreateView中扩展RecyclerView的Fragment中尝试此方法
recyclerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
v.onTouchEvent(event);
return true;
}
});发布于 2017-08-17 15:21:05
只需将其视为BottomSheetDialog,并简单地禁用其在触摸时的拖动或滑动。
创建BottomSheetDialog时,它会自动将您的布局包装在CoordinatorLayout 中,所以如果您想从视图中获取行为,请调用
最终视图行为=BottomSheetBehavior.from(( BottomSheetBehavior ) view.getParent());
然后通过这种行为,你可以做你需要做的事情。
final BottomSheetBehavior behavior = BottomSheetBehavior.from((View) view.getParent());
behavior.setHideable(false);
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
});这对me.Hope很有帮助。
https://stackoverflow.com/questions/40904724
复制相似问题