当前位置:网站首页>Bottomsheetdialogfragment conflicts with listview recyclerview Scrollview sliding
Bottomsheetdialogfragment conflicts with listview recyclerview Scrollview sliding
2022-04-23 07:10:00 【Zhang Hailong_ China】
1. The phenomenon :BottomSheetDialogFragment You can slide up and down through gestures , frequently-used ListView RecyclerView ScrollView Can also slide up and down , There will be some conflict problems , such as ScrollView When you want to slide down ,ScrollView The content doesn't slide , however BottomSheetDialogFragment It was pulled down and closed .
2. Source code analysis
open BottomSheetDialog Source code :
private View wrapInBottomSheet(int layoutResId, View view, ViewGroup.LayoutParams params) {
final FrameLayout container = (FrameLayout) View.inflate(getContext(),
R.layout.design_bottom_sheet_dialog, null);
final CoordinatorLayout coordinator =
(CoordinatorLayout) container.findViewById(R.id.coordinator);
if (layoutResId != 0 && view == null) {
view = getLayoutInflater().inflate(layoutResId, coordinator, false);
}
FrameLayout bottomSheet = (FrameLayout) coordinator.findViewById(R.id.design_bottom_sheet);
mBehavior = BottomSheetBehavior.from(bottomSheet);
mBehavior.setBottomSheetCallback(mBottomSheetCallback);
mBehavior.setHideable(mCancelable);
if (params == null) {
bottomSheet.addView(view);
} else {
bottomSheet.addView(view, params);
}
//... Omit
return container
Incoming View Will eventually be add Into one FrameLayout Of bottomSheet in , And then through bottomSheet To instantiate a BottomSheetBehavior, And then give this mBehavior Set up a mBottomSheetCallback, Let's see what it is :
private BottomSheetBehavior.BottomSheetCallback mBottomSheetCallback
= new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet,
@BottomSheetBehavior.State int newState) {
if (newState == BottomSheetBehavior.STATE_HIDDEN) {
cancel();
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
};
3. Solution :
3.1 Method 1: rewrite BottomSheetCallback The logic of judgment in
private BottomSheetBehavior.BottomSheetCallback mBottomSheetCallback
= new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet,
@BottomSheetBehavior.State int newState) {
if (newState == BottomSheetBehavior.STATE_DRAGGING) {// When judged as drag down behavior , Then the forced setting status is expanded
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED );
}
LogUtil.e(TAG, "onStateChanged——>" + newState);
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
LogUtil.e(TAG, "onSlide——>" + slideOffset);
}
};
3.2 Method 2 : Direct, simple and rough :
Just in RecyclerView ListView A layer of outer covering NestedScrollViewl, If it was ScrollView Replace with NestedScrollViewl

版权声明
本文为[Zhang Hailong_ China]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230607201372.html
边栏推荐
猜你喜欢

组件化学习(3)ARouter中的Path和Group注解

JVM basics you should know

【机器学习】笔记 4、KNN+交叉验证

./gradlew: Permission denied

Dolphinscheduler源码包src.tar.gz解压问题

Chaos帶你快速上手混沌工程

Build a cloud blog based on ECS (polite experience)

基于BottomNavigationView实现底部导航栏

Dolphinscheduler调度spark任务踩坑记录

Build an OSS based image sharing website - polite feedback
随机推荐
Recyclerview 批量更新View:notifyItemRangeInserted、notifyItemRangeRemoved、notifyItemRangeChanged
oracle undo使用率高问题处理
ORACLE环境遇到的ORA-600 [qkacon:FJswrwo]
sys.dbms_scheduler.create_job创建定时任务(功能更强大丰富)
Antd Design Form表单检验
MySQL笔记1_数据库
MySQL笔记5_操作数据
RAC环境数据库节点参数设置不当导致监听无法连接问题排查
Exception record-9
Exception record-14
Abnormal record-15
oracle 修改默认临时表空间
timestamp隐式转换问题导致索引列未使用问题分析
[exynos4412] [itop4412] [android-k] add product options
Abnormal record-12
Exception record-5
Dolphinscheduler配置Datax踩坑记录
MarkDown基础语法笔记
oracle分区的相关操作
JVM basics you should know