popupwindow 小小记

来源:互联网 发布:正确的日干支推算法 编辑:程序博客网 时间:2024/06/05 09:48

实现popupwindow 首先继承PopupWindow

在子类的构造方法:public GroupListPopupWindow(Context context) 方法中

一定要添加:

// 添加菜单视图this.setContentView(mRootView);//// 不设置width和height显示不出来this.setWidth(LayoutParams.WRAP_CONTENT);this.setHeight(LayoutParams.WRAP_CONTENT);this.setFocusable(true);// menu菜单获得焦点 如果没有获得焦点menu菜单中的控件事件无法响应this.setBackgroundDrawable(new BitmapDrawable());// http://blog.csdn.net/hustpzb/article/details/7891803,没有这个点击外面关不了popupwindow

显示时,调用

mGroupListPopupWindow.showAsDropDown(layoutInsideCenter, 0, 0);

会将layoutInsidecenter的左下角作为popupwindow的左上角锚点,popupwindow在layoutInsidecenter下面显示。后面的两个值是x方向和y方向的偏移,注意单位是dp!

0 0
原创粉丝点击