public MyDialog(Context context, int width, int height, View layout) { super(context, R.style.DialogTheme); setContentView(layout); Window window = getWindow(); WindowManager.LayoutParams params = window.getAttributes(); params.width = width; params.height = height; params.gravity = Gravity.CENTER; //显示的位置 window.setAttributes(params); }
使用:
int width = getResources().getDisplayMetrics().widthPixels;//获取popwindow展示的宽 int height = getResources().getDisplayMetrics().heightPixels;//获取popwindow展示的高 MyDialog mMyDialog = new MyDialog(this, width * 3 / 4 , height * 3 / 5, view, R.style.DialogTheme); mMyDialog.setCancelable(true); mMyDialog.show();
来源:CSDN
作者:星枫丶
链接:https://blog.csdn.net/qq_26446715/article/details/104313479