开头
今天遇到一个很坑的问题,视觉让我把弹窗做成圆角的,so easy啊,做一个圆角背景就好了嘛!然后视觉还说.9图都帮我做好了,省了,连背景都不用做了,直接用!!
结果:
![](https://img.haomeiwen.com/i3212378/f2f26b6020a603b3.png)
外面的边是什么鬼!!
排查方法:
打开Tool-->Layout Inspector检查一下布局吧
![](https://img.haomeiwen.com/i3212378/e72dbfaf241b6087.png)
从图片上看是有两个背景,或者或外面有一层边距。
设置padiing 为0,-- 无效
那就是有两个背景了。
结论:
其实我们在xml里面设置的背景是LinearLayout的,但是我们要设置的是PupopWindow的整个窗体背景啊,当然不能在xml里设置啦。
最后修改代码附上:
if (mPopupWindow == null){ mPopupWindow = new PopupWindow(mContext); mPopupWindow.setBackgroundDrawable(mContext.getDrawable(R.drawable.popup_menu_bg));//设置窗体背景 mPopupWindow.setElevation(10);//设置外边阴影 mPopupWindow.setFocusable(true); mPopupWindow.setOutsideTouchable(true);//点击外部可消失 mPopupWindow.setWidth(width);//设置宽度 mPopupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); }
![](https://img.haomeiwen.com/i3212378/6f7eac771703566b.png)
网友评论