public PopupWindow (View contentView, int width, int height)
Create a new non focusable popup window which can display the contentView . The dimension of the window must be passed to this constructor.
The popup does not provide any background. This should be handled by the content view.
Parameters
contentView width heightthe popup's content |
the popup's width |
the popup's height |
public PopupWindow (View contentView)
Create a new non focusable popup window which can display the contentView . The dimension of the window are (0,0).
The popup does not provide any background. This should be handled by the content view.
Parameters
contentViewthe popup's content |
当然你也可以再后面初始化popupWindow时,再调用其他功能函数进行设置。
窗体显示函数:
void | showAsDropDown (View anchor, int xoff, int yoff)
Display the content view in a popup window anchored to the bottom-left corner of the anchor view offset by the specified x and y coordinates. |
void | showAsDropDown (View anchor)
Display the content view in a popup window anchored to the bottom-left corner of the anchor view. |
void | showAtLocation (View parent, int gravity, int x, int y)
Display the content view in a popup window at the specified location. |
具体就两种方式:showAsDropDown 和 showAtLocation ,
showAsDropDown
- 就是以触发弹出窗弹出的那个view为基准 ,弹出 后显示在那个view的正下方,view的下方,并是水平中央
- 假如有偏移的参数,则显示的位置按参数进行x,y坐标的偏移, 参数xoff , yoff,默认为0,传入负数向左偏移,正数向右偏移
showAtLocation
- 自定义弹出的位置,参数列里有parent,与 showAsDropDown的 anchor不同性质,注释里是这样说的: a parent view to get the
getWindowToken()
token from,也就是与弹出的位置没有直接关联;但是这个parent必须是一个activityl里的View,不然会出错 - 参数gravity,大致与TextView的gravity一样,指示控件的对齐方向,当然这里的基准对象当然是DisplayWindow啦;
- 参数 x,y 就是指示弹出窗实际的显示坐标了,但这两个参数依赖参数gravity,指示基准对齐后的xy偏移值,这点与showAsDropDown 的一样