1. 程式人生 > >DialogFragment如何設定大小和位置

DialogFragment如何設定大小和位置

getDialog().getWindow().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
        WindowManager.LayoutParams lp = getDialog().getWindow().getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        if (mHeight == 0) {
            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        } else {
            lp.height = mHeight;
        }
        getDialog().getWindow().setAttributes(lp);

這樣子放在onCreateView()就可以了。

參照:

http://stackoverflow.com/questions/9698410/position-of-dialogfragment-in-android?rq=1