在一个BottomSheetDialogFragment里面加载webfragment, webfragment里面加载H5,
然后发现之前的老链接打开正常,新链接不行,打开看不到h5, 刚开始还以为是webview组件的问题加载不出来,查看页面结构才找到问题,是为了解决滑动冲突,在加载webfragment的fragmentlayout外面报了一层NestScrowView导致的,网上有很多这个问题的解答。
比如:
我的解决办法是,既然web本身是可以滑动的,就把外面的BottomSheetDialogFragment的滑动禁掉了,设置了固定高度。里面h5可以自由的滑动,就不用包一层NestedScrollView了~
还有个问题,就是加载h5后,这个dialogfragment上面圆角展示,但是不管是在xml里面设置drawable还是在代码里设置,还是设置在最外层的父布局上,加载完h5后弹框页面还是直角的。。。。最后没办法了,最外面又裹了一层cardview 😭
bottomtsheetdialogfragment禁止滑动的代码:
@Override
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
if (dialog != null) {
View bottomSheet = dialog.findViewById(R.id.design_bottom_sheet);
if (bottomSheet != null && bottomSheet.getLayoutParams() != null) {
bottomSheet.getLayoutParams().height = DisplayUtil.dp2px(getContext(), 600);
}
dialog.getWindow().setDimAmount(0.7f);
dialog.setCancelable(false);
}
final View view = getView();
if (view != null) {
view.post(() -> {
View parent = (View) view.getParent();
if (parent != null) {
ViewGroup.LayoutParams layoutParams = parent.getLayoutParams();
if (layoutParams instanceof CoordinatorLayout.LayoutParams) {
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) layoutParams;
CoordinatorLayout.Behavior behavior = params.getBehavior();
if (behavior instanceof BottomSheetBehavior) {
((BottomSheetBehavior) behavior).setPeekHeight(DisplayUtil.dp2px(getContext(), 600));
}
}
parent.setBackgroundColor(Color.TRANSPARENT);
}
});
}
}