1 | Popwindow的动画设置 window.setAnimationStyle(R.style.AnimationFade); |
3、PopupWindow的焦点设置
1 2 3 | window.setFocusable(true); //设置PopupWindow可获得焦点 window.setTouchable(true); //设置PopupWindow可触摸 window.setOutsideTouchable(true); //设置非PopupWindow区域可触摸 |
4、PopupWindow的显示及显示位置设置
1 2 | window.showAtLocation(); window.showAsDropDown(); |
Android下PopupWindow隐藏及显示(showAtLocation/showAsDropDown)
下面说说PopupWindow的如何隐藏、显示及显示位置(showAtLocation/showAsDropDown)。
1、PopupWindow的隐藏
1 2 3 4 | final PopupWindow window = mPageStatWin; if(null != window && window.isShowing()) { } |
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的左上角来显示。