View view = View.inflate(context, R.layout.layout_popou_window, null); //获取PopupWindow中View的宽高 view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); PopupWindow popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setFocusable(true);//popupwindow设置焦点 popupWindow.setOutsideTouchable(true);//点击外面窗口消失 //获取点击View的坐标 int[] location = new int[2]; v.getLocationOnScreen(location); int x = location[0] - DensityUtil.dip2px(activity, 80 * 2);
//显示在左方 popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, x, location[1]);