View view = getLayoutInflater().inflate(R.layout.popup_windwos_layout, null); PopupWindow pp = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); //设置背景图片 pp.setBackgroundDrawable(getResources().getDrawable(R.drawable.er)); //设置动画 pp.setAnimationStyle(android.R.style.Animation_Translucent); //透明度 pp.getBackground().setAlpha(100); //只有点到旁边才可以消失 pp.setOutsideTouchable(true); //获取到焦点 pp.setFocusable(true); //可以被触摸 pp.setTouchable(true); //设置屏蔽软键盘 pp.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); //相对于父控件显示 pp.showAtLocation(v, Gravity.BOTTOM, 0, 0); //获取屏幕宽高的方法 DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int width = dm.widthPixels; int height = dm.heightPixels; Toast.makeText(main.this, width + ">>" + height, Toast.LENGTH_SHORT).show();