这是popupWindow的几个显示方法:
showAsDropDown(View anchor),相对某个控件的位置(正左下方),无偏移
showAsDropDown(View anchor, int xoff, int yoff):相对某个控件的位置,有偏移
showAtLocation(View parent, int gravity, int x, int y):相对于父控件的位置(例如正中央Gravity.CENTER,下方Gravity.BOTTOM等),可以设置偏移或无偏移
关闭功能:
1、可以点击popupWindow之外的地方进行关闭
2、点击back键关闭
关闭popupWindow:
mPopupWindow=new PopupWindow(popupWindow, ppWidth, ppHeight,true);点击返回键时可以关闭mPopupWindow.setFocusable(true);点击返回键时可以关闭
mPopupWindow.setOutsideTouchable(true);
mPopupWindow.setBackgroundDrawable(new BitmapDrawable());点击popupWindow之外的地方可以关闭