在最近的项目中要用到BottomSheetDialogFragment,因为需要在BottomSheetDialogFragment生命周期中处理一些逻辑,所以选择了BottomSheetDialogFragment,但是在写完后发现,BottomSheetDialogFragment弹窗,底部还有一部分显示不全,需要往上面滑动一下才能显示完全,查了一下资料说是发生了冲突,然后谷歌了一下,找到了解决办法:
在BottomSheetDialogFragment的 onCreateView中添加如下代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment.
getDialog().setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
BottomSheetDialog d = (BottomSheetDialog) dialog;
FrameLayout bottomSheet = (FrameLayout) d.findViewById(R.id.design_bottom_sheet);
CoordinatorLayout coordinatorLayout = (CoordinatorLayout) bottomSheet.getParent();
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
bottomSheetBehavior.setPeekHeight(bottomSheet.getHeight());
coordinatorLayout.getParent().requestLayout();
}
});
return inflater.inflate(R.layout.fragment_bs_image_picker, container);
}
这样就可以解决!记录一下。