dialogfragment设置底部没有和屏幕有间隔

 @Override
    public void onStart() {
        super.onStart();
        Window window = getDialog().getWindow();
        if (window != null) {
            //设置 window 的背景色为透明色.
            //如果通过 window 设置宽高时,想要设置宽为屏宽,就必须调用下面这行代码。
            window.setBackgroundDrawable(new ColorDrawable(0xff000000));
            WindowManager.LayoutParams attributes = window.getAttributes();
            //在这里我们可以设置 DialogFragment 弹窗的位置
            attributes.gravity = Gravity.BOTTOM;
            //我们可以在这里指定 window的宽高
            Display display = getActivity().getWindowManager().getDefaultDisplay();
            attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
            // 设置窗体的高度
//        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
            attributes.height = Utils.getScreenHeight(mContext)*3/4;
            window.getDecorView().setPadding(0, 0, 0, 0);
            //设置 DialogFragment 的进出动画
//            attributes.windowAnimations = R.style.DialogAnimation;
            window.setAttributes(attributes);
        }
    }

你可能感兴趣的:(安卓)