PopupWindow 一些注意事项
//加载布局
View inflate = LayoutInflater.from(context).inflate(resource, null);
//做布局中控件加载、数据处理
initPopupWindowData(inflate);
//创建PopupWindow对象
PopupWindow popupWindow = new PopupWindow(inflate, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//设置弹窗是否是焦点
popupWindow.setFocusable(true);
//设置弹窗外部背景透明
popupWindow.setBackgroundDrawable(new BitmapDrawable());
//设置外部可点击消失
popupWindow.setOutsideTouchable(true);
//创建画笔
Point point = new Point();
//获取屏幕宽高
getWindowManager().getDefaultDisplay().getSize(point);
//int point.y 屏幕的高度
//int point.x 屏幕的宽度
popupWindow.setHeight(point.y/2);
popupWindow.setWidth(point.x/4);
//弹窗显示的位置
//在哪个控件的下方
popupWindow.showAsDropDown(resource);
//基于哪个父容器 在父容器的显示位置 可以用 | 链接 如:右上方Gravity.RIGHT | Gravity.TOP
//后面两个参数为横纵向偏移量 相当于XML中的 magin
popupWindow.showAtLocation(resource, Gravity.RIGHT | Gravity.TOP, 0, 0);