之前做项目的时候也碰到过PopupWindow从底部弹出,界面底部的UI有一部分被遮盖了。之前碰到这个问题的大多是类似华为手机之类的有虚拟按键的手机。可是这次我用来运行的机子是模拟机,也没有虚拟按键之类的东东。花了一点时间处理了,所以记录一下。

首先:我先试试机子有没有NavigationBar,如果有我就按照以前的方法处理(判断手机是否有物理按钮,有则计算底部的NavigationBar高度,最后设置View边距)

public int getNavigationBarHeight() {boolean hasMenuKey = ViewConfiguration.get(this).hasPermanentMenuKey();boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);if (!hasMenuKey && !hasBackKey) {Resources resources = getResources();int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");//获取NavigationBar的高度 int height = resources.getDimensionPixelSize(resourceId);return height;}else{return 0;}
}

我运行了上面的代码,返回的是0  没有NavigationBar。好气啊。。怎么办怎么办怎么办!!!!!

其次: 设置popupWindow.setClippingEnabled(false)

setClippingEnabled 这方法是什么啊。

官方的解释:

Allows the popup window to extend beyond the bounds of the screen. By default the window is clipped to the screen boundaries. Setting this to false will allow windows to be accurately positioned.
If the popup is showing, calling this method will take effect only the next time the popup is shown or through a manual call to one of the update() methods.  Parameters:
enabled false if the window should be allowed to extend outside of the screen   

翻译:

允许弹出窗口扩展到屏幕的边界之外。默认情况下,窗口被剪切到屏幕边界。将其设置为false将使windows能够准确定位。

然后就变成了这样:

好气啊 这次好像是UI覆盖了返回键了。设置这个方法以后UI网上移动了一小部分,可是还是没有解决。。。

最后:  检查代码

private void initPicPop() {if (mPopPicNotify == null) {DisplayMetrics dm = new DisplayMetrics();getWindowManager().getDefaultDisplay().getMetrics(dm);mPopPicNotify = new PopupWindow(dm.widthPixels, dm.heightPixels);View popView = LayoutInflater.from(this).inflate(R.layout.layout_upload, null);TextView tvTackPic = (TextView) popView.findViewById(R.id.tv_photo);TextView tvAlbum = (TextView) popView.findViewById(R.id.tv_album);TextView tvCancel = (TextView) popView.findViewById(R.id.tv_cancel);mPopPicNotify.setContentView(popView);mPopPicNotify.setFocusable(true);mPopPicNotify.setBackgroundDrawable(new PaintDrawable(getResources().getColor(R.color.color_60000000)));mPopPicNotify.setClippingEnabled(false);mPopPicNotify.setOutsideTouchable(false);mPopPicNotify.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);tvTackPic.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {useCamera();} else {openPath();}}});tvAlbum.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Intent albumIntent = new Intent(Intent.ACTION_PICK, null);albumIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");startActivityForResult(albumIntent, REQUEST_ALBUM_OK);}});tvCancel.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {mPopPicNotify.dismiss();}});}mPopPicNotify.showAtLocation(mRootView, Gravity.CENTER, 0, 0);}

看了几遍,也没有什么错误啊。最后试着重新创建PopupWindow

mPopPicNotify = new PopupWindow(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);

运行:

解决

但是,原因还不是很清楚。

DisplayMetrics dm = new DisplayMetrics();getWindowManager().getDefaultDisplay().getMetrics(dm);

mPopPicNotify = new PopupWindow(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);

有什么区别,还有待我去学习。

PopupWindow底部弹出,底部UI被遮盖问题相关推荐

  1. 【Android】Activity和PopupWindow都实现从底部弹出或滑出选择菜单或窗口

    使用Activity和PopupWindow都实现从底部弹出或滑出选择菜单或窗口 [Android]测试与popwindow PopupWindow转载自:Android PopupWindow实现从 ...

  2. android PopupWindow实现从底部弹出或滑出选择菜单或窗口

    android PopupWindow实现从底部弹出或滑出选择菜单或窗口 http://www.open-open.com/lib/view/open1379383271818.html http:/ ...

  3. popupwindow 底部弹出+背景半透明

    首先是布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:androi ...

  4. 底部弹出PopupWindow并且背景变为半透明效果

    来自:http://blog.csdn.net/LANG791534167/article/details/48985101 先来看看运行效果图 [方式一]实现从底部弹出PopupWindow 原理: ...

  5. Android DialogFragment实现底部弹出菜单效果

    底部弹出式菜单, 可以使用PopupWindow来做,也可以用自定义View来做.当然这里采用DialogFragment来做. DialogFragment是3.0之后引入的,使用DialogFra ...

  6. Android之popWindows底部弹出挡住了华为虚拟键盘问题

    1.问题 使用popWindows的时候底部弹出遮挡华为虚拟键盘 2.解决办法 在调用下面代码之前 popupWindow.showAtLocation 加上如下的代码进行设置 popupWindow ...

  7. Android仿IOS封装通用的弹出框Dialog和底部弹出列表选择框 仿美团顶部条件筛选框 附自定义ViewGroup

    弹出框 背景 提示与询问弹出框 实现 使用 列表选择框 实现 使用 顶部条件筛选框 实现 自定义ViewGroup 使用 总结 背景 鉴于Android提供的默认弹出框很一般,IOS的弹出框样式还不错 ...

  8. Android——完全自定义 底部弹出支付页面

    近期博主在网上随便搜了一番,发现很多实现 底部弹出支付页面的大多数都用的,自定义PopupWindow 去实现的,里面复杂的逻辑看得我不想看,很多对自定义不熟悉伙伴们,看到 自定义 这三个字就有种血脉 ...

  9. flutter实现底部弹出框以及特色功能

    今天项目中要实现底部弹出框并且实现圆角功能,先来预览一下 可以看出实现的公告有 底部圆角,以及朋友圈,微信转发等 实现逻辑我直接代码列出 定义 List<String> nameItems ...

最新文章

  1. pycharm使用import numpy报错
  2. Java:从Java 8开始受益于内联类属性
  3. 【kafka】kafka 2.4 static membership功能 group.instance.id
  4. BAT面试问题--算法工程师(机器学习)
  5. C++C面试题100道分析(21-40)
  6. mysql关键字了解
  7. 关于EasyExcel 优化,实现格式自定义,数据字典自动转化。
  8. CMOS门电路(OD门、传输门、双向模拟开关、三态门)
  9. iOS 应用测试总结
  10. 黑色星期五c语言程序,黑色星期五C语言实现
  11. 响应式开发(六)-----Bootstrap CSS----------Bootstrap文本排版
  12. 北京仁源欣生获200万美元天使轮融资,和玉资本领投
  13. OLED屏幕应用实验
  14. dxdiag是什么 dxdiag命令怎么用
  15. AutoCAD Civil 3D中的对象和标签
  16. 华为颇无奈,徕卡或离它而去而与小米合作
  17. 如何用帮助中心自助服务页面提高客户使用体验
  18. 踱步狼注释移除状态机算法2019.10
  19. Redis Eviction policies (驱逐策略)
  20. VolumeUI音量调节对话框

热门文章

  1. 【ubuntu】解决 Certificate verification failed: The certificate is NOT trusted
  2. tiptop 编译运行_TIPTOP MPS(amsp500)运行流程
  3. 读 Samuel Enoch Stumpf 之《西方哲学史》
  4. 普通人千万别把打工当赚钱,打工只是赚钱的一种方法
  5. qpython oh下载_QPython OH
  6. qpython3l最新版下载_qpython3l
  7. EasyFlash 里的 EF_WRITE_GRAN
  8. 数据链路层的功能与设备
  9. 仓库标准作业流程与WMS系统规划
  10. ONVIF 获取RTSP URL过程