PopupWindow是Android中实现弹窗效果的一个类:
1.实例化一个PopupWindow
View contentView = getLayoutInflater().inflate(R.layout.popwindow, null);
PopupWindow popupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
2.PopupWindow的显示方式
popupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
第一个参数是PopupWindow显示在那个view上,第二个参数是PopupWindow的显示位置,第三四个参数是PopupWindow的偏移量
另外一种显示方式是showAsDropDown(View anchor) 或showAsDropDown(View anchor, int xoff, int yoff)