Android BottomSheetDialogFragment 内容显示不全

       在最近的项目中要用到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);
    }

这样就可以解决!记录一下。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值