Android中改变dialog的显示的位置和大小

时间:2022-11-01 11:09:03
private void setDialogSize(Dialog dg) {
    Window dialogWindow = dg.getWindow();
    WindowManager.LayoutParams lp = dialogWindow.getAttributes();
    dialogWindow.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    dialogWindow.setGravity(Gravity.LEFT | Gravity.TOP);
    //显示的坐标
    lp.x = 150;
    lp.y = 50;
    int width = getResources().getDimensionPixelOffset(R.dimen.d_width);
    int height = getResources().getDimensionPixelOffset(R.dimen.d_height);
    //dialog的大小
    lp.width = width;
    lp.height = height;
    dialogWindow.setAttributes(lp);
}

 Android中改变dialog的显示的位置和大小