欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

安卓-BottomSheetDialogFragment高度设置

程序员文章站 2022-07-03 21:52:46
要设置Dialog的高度,重写onStart() 方法即可 private BottomSheetBehavior mBottomSheetBehavior; @Override public void onStart() { super.onStart(); Dialog dialog = getDialog(); if (dialog != null) { View bottomSh...

要设置Dialog的高度,重写onStart() 方法即可

    private BottomSheetBehavior<View> mBottomSheetBehavior;
    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();

        if (dialog != null) {
            View bottomSheet = dialog.findViewById(R.id.design_bottom_sheet);
            bottomSheet.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
        }
        final View view = getView();
        view.post(new Runnable() {
            @Override
            public void run() {
                View parent = (View) view.getParent();
                CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) (parent).getLayoutParams();
                CoordinatorLayout.Behavior behavior = params.getBehavior();
                mBottomSheetBehavior = (BottomSheetBehavior) behavior;
                mBottomSheetBehavior.setPeekHeight(view.getMeasuredHeight());

                parent.setBackgroundColor(Color.TRANSPARENT);
            }
        });
    }

但是,有一点很重要,layout xml各个项目必须是从上往下画的

本文地址:https://blog.csdn.net/weixin_48576311/article/details/107531581

相关标签: 安卓