转载:http://orgcent.com/android-popupwindow-showasdropdown-showatlocation/
上一篇对PopupWindow的用法(位置、动画、焦点)做了详细介绍,具体查看Android中PopupWindow的用法(位置、动画、焦点)。下面说说PopupWindow的如何隐藏、显示及显示位置(showAtLocation/showAsDropDown)。
1、PopupWindow的隐藏
1
2 3 4 |
final PopupWindow window = mPageStatWin;
if(null != window && window.isShowing()) { win.dismiss(); } |
2、PopupWindow的显示及位置设置
1
|
window.showAtLocation(parent, Gravity.RIGHT | Gravity.BOTTOM, 10,10);
|
第一个参数指定PopupWindow的锚点view,即依附在哪个view上。
第二个参数指定起始点为parent的右下角,第三个参数设置以parent的右下角为原点,向左、上各偏移10像素。
第二个参数指定起始点为parent的右下角,第三个参数设置以parent的右下角为原点,向左、上各偏移10像素。
1
2 3 4 |
//将PopupWindow作为anchor的下拉窗口显示。即在anchor的左下角显示
window.showAsDropDown(anchor); //xoff,yoff基于anchor的左下角进行偏移。 window.showAsDropDown(anchor, xoff, yoff); |
如果没有充足的空间显示PopupWindow,那么PopupWindow的左下角将位于anchor的左上角来显示。