android PopupWindow显示位置

PopupWindow的显示及位置设置
 window.showAtLocation(parent, Gravity.RIGHT | Gravity.BOTTOM, 10,10); 第一个参数指定PopupWindow的锚点view,即依附在哪个view上。
第二个参数指定起始点为parent的右下角,第三个参数设置以parent的右下角为原点,向左、上各偏移10像素。 //将PopupWindow作为anchor的下拉窗口显示。即在anchor的左下角显示

在控件的其他方向上显示只需修改最后一行代码:

下方:popupWindow.showAsDropDown(v);

左边:

popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]-popupWindow.getWidth(), location[1]);  

右边:

popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0]+v.getWidth(), location[1]);  

 

posted @ 2015-08-26 11:07  星辰之力  阅读(552)  评论(0编辑  收藏  举报