android开发 PopupWindow 设置充满屏幕

时间:2021-06-13 14:12:58
View qrcode_view = this.getLayoutInflater().inflate(R.layout.taskdetail_qrcode,null);

                final PopupWindow qrcodePop = new PopupWindow(qrcode_view,getWindowManager().getDefaultDisplay().getWidth(),getWindowManager().getDefaultDisplay().getHeight());
//qrcodePop.showAsDropDown(v);
qrcodePop.showAtLocation(v,Gravity.CENTER,Gravity.FILL_HORIZONTAL,Gravity.FILL_VERTICAL);
ImageView qrcode = (ImageView)qrcode_view.findViewById(R.id.qrcode_image);
int qr_width = BitmapUtil.Dp2Px(this,200);
qrcode.setImageBitmap(QRCodeUtil.createImage(globalVal.BASE_URL+"/"+taskInfo.task_id,qr_width,qr_width));
qrcode_view.findViewById(R.id.close_qrcode).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
qrcodePop.dismiss();
}
}
);

注意获取屏幕的高度和宽度:

宽度:getWindowManager().getDefaultDisplay().getWidth();

高度:getWindowManager().getDefaultDisplay().getHeight();