pro*_*m85 12 android bottom-sheet
我有BottomSheetDialogFragment
一个RecyclerView
.问题是,我想禁用拖动关闭功能,BottomSheetDialogFragment
只要RecyclerView
不向上滚动(目前我无法滚动我RecyclerView
的尝试将始终关闭BottomSheetDialogFragment
).任何想法如何实现这一目标?
Bro*_*Han 11
可以通过这种方式解决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>
Run Code Online (Sandbox Code Playgroud)
小智 7
Fragment
在你的扩展RecyclerView
中尝试这个onCreateView
recyclerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
v.onTouchEvent(event);
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
只需向您的布局添加一个 (!) 属性:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/receiversList"
android:nestedScrollingEnabled="false"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)
android:nestedScrollingEnabled="false"
做所有的工作。另外,如果你环绕你的RecyclerView
with SwipeRefreshLayout
- 刷新功能将继续工作。即使您将布局置于更复杂的视图中,您也BottomSheetDialog
将继续支持向下拖动以关闭行为(如果在RecyclerView
&之外发生向下滑动手势的触摸SwipeRefreshLayout
)。
小智 1
更改 setupDialog 方法中 BottomSheetDialogFragment 中的行为:
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
final CoordinatorLayout.Behavior behavior = layoutParams.getBehavior();
if (behavior != null && behavior instanceof BottomSheetBehavior) {
((BottomSheetBehavior) behavior).setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_HIDDEN) {
dismiss();
}
if (newState == BottomSheetBehavior.STATE_DRAGGING) {
((BottomSheetBehavior) behavior).setState(BottomSheetBehavior.STATE_EXPANDED);
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4896 次 |
最近记录: |