美文网首页
PopupWindow使用showAsDropDown低版本不显

PopupWindow使用showAsDropDown低版本不显

作者: 犇犇灬zk | 来源:发表于2022-04-12 13:57 被阅读0次

问题记录:

自定义PopupWindow 继承PopupWindow,使用showAsDropDown方法弹出时,在Android高版本中可以正常使用,在使用低版本(Android5.1.1)发现弹出后width 和height 都是0。

xml文件中根布局使用的layout_width和layout_height 值为wrap_content。

问题原因:

xml根布局设置的wrap_content的并不会作用的PopupWindow的window上面,在低版本中需要手动设置PopupWindow的width和height,即:

1.如果自定PopupWindow,可以在构造函数中 显示 setWidth(ViewGroup.LayoutParams.WRAP_CONTENT)和setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)

2.如果使用系统PopupWindow,可以在创建的 popupWindow对象设置,即:

popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);        popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

相关文章

网友评论

      本文标题:PopupWindow使用showAsDropDown低版本不显

      本文链接:https://www.haomeiwen.com/subject/npzgsrtx.html