您的位置:首页 > 运维架构

使用popupwindow的坑(不显示)

2018-02-03 10:18 169 查看
很多时候你可能会遇到popupwindow不显示或是一部分手机能显示一些不能显示的情况,那恭喜你看到了这篇文章。


最开始我创建popupwindow的方式


代码如下

//肉眼看上去没什么问题,果然拿出我的小米note跑起来也是正常的,但是偏偏来个三星和魅族的一些手机就显示不了
View view = LayoutInflater.from(this).inflate(R.layout.choice_rider_num, null);
window = new PopupWindow(this);
window.setContentView(view);
window.setOutsideTouchable(false);
window.setFocusable(true);
// 实例化一个ColorDrawable颜色为半透明
window.setBackgroundDrawable(null);
window.setAnimationStyle(R.style.mypopwindow_anim_style);
window.showAtLocation(v, Gravity.BOTTOM, 0, 0);


仔细研究后发现是没有给popupwindow设置宽高导致的,于是

window = new PopupWindow(this);
window.setContentView(view);
//设置宽高
window.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
window.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
window.setOutsideTouchable(false);
window.setFocusable(true);
window.setAnimationStyle(R.style.mypopwindow_anim_style);
window.showAtLocation(v, Gravity.BOTTOM, 0, 0);


解决啦


同理你也可以

window = new PopupWindow(v, WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT);
window.setContentView(view)
window.setOutsideTouchable(false);
window.setFocusable(true);
// 实例化一个ColorDrawable颜色为半透明
window.setBackgroundDrawable(null);
window.setAnimationStyle(R.style.mypopwindow_anim_style);
window.showAtLocation(v, Gravity.BOTTOM, 0, 0);

作者:laer_L链接:https://www.jianshu.com/p/a18215850a62
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android Popupwindow