Android 自定义通用Dialog
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);