Android 7.0系统 PopupWindow的bug
来源:互联网 发布:统计学数据分析案例题 编辑:程序博客网 时间:2024/05/17 22:53
起初产品经理说过一次,因为是刚入职接手的项目所以,我当时没太在意这个bug,当时报备的是华为手机有这种问题,其他机型没有,我当时就想应该是系统兼容性问题,毕竟国内系统改的乱七八糟,后来发现oppo也出现了,就是PopupWindow显示是从顶部弹出的,我看下代码,没什么问题,但是小米就没问题,后来google了一波是系统bug,于是就做兼容性处理,分分钟奏效
我们预期的效果图:
但是android 7.0却是这样:
其实原因就是android 7.0系统源码对popwindow处理存在bug,以前我接手的代码是这样的:
private void showPopup(int position) { View tView = mViewArray.get(selectPosition).getChildAt(0); if (tView instanceof ViewBaseAction) { ViewBaseAction f = (ViewBaseAction) tView; f.show(); } if (popupWindow.getContentView() != mViewArray.get(position)) { popupWindow.setContentView(mViewArray.get(position)); } popupWindow.showAsDropDown(this, 0, 0); }
以上代码是没有对7.0做处理的。可能上一个开发还没test,就离职了,那就让我来填这个坑吧(2333)
兼容处理代码:
private void showPopup(int position) { View tView = mViewArray.get(selectPosition).getChildAt(0); if (tView instanceof ViewBaseAction) { ViewBaseAction f = (ViewBaseAction) tView; f.show(); } if (popupWindow.getContentView() != mViewArray.get(position)) { popupWindow.setContentView(mViewArray.get(position)); } //TODO Android 7.x中,PopupWindow高度为match_parent时,会出现兼容性问题,需要处理兼容性 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { int[] location = new int[2]; // 记录anchor在屏幕中的位置 this.getLocationOnScreen(location); int offsetY = location[1] + this.getHeight(); //TODO Android 7.1中,PopupWindow高度为 match_parent 时,会占据整个屏幕,故而需要在 Android 7.1上再做特殊处理 if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1) { int screenHeight = displayHeight; // 获取屏幕高度 popupWindow.setHeight(screenHeight - offsetY); // 重新设置 PopupWindow 的高度 } popupWindow.showAtLocation(this, Gravity.NO_GRAVITY, 0, offsetY); } else { popupWindow.showAsDropDown(this); } }
这样就达到预期效果了。
阅读全文
0 0
- Android 7.0系统 PopupWindow的bug
- Mark一下 PopupWindow 的系统BUG
- 安卓7.0中popupWindow的BUG
- android 7.0 PopupWindow bug修复,测试没啥问题
- 解决PopupWindow在7.0以上位置不正确的bug
- 解决PopupWindow在7.0以上位置不正确的bug
- Android系统的一些bug
- android PopupWindow重写系统菜单
- Android PopupWindow重写系统菜单
- Popupwindow在Android 7.0以上系统位置显示不对的解决办法
- Android系统中开机启动时候的使用说明popupwindow是吗
- popupwindow在不同theme时候的bug
- android PopupWindow引起外部view点击事件的一个诡异的bug
- PopupWindow 在 Android N(7.0) 的兼容性问题
- PopupWindow 在 Android N(7.0) 的兼容性问题
- Android PopupWindow的使用
- Android PopupWindow的使用
- Android PopupWindow的使用!!!
- POJ 2594 浅谈可相交的二分图DAG最小路径覆盖
- memcache的使用
- 关于Ubuntu下MySQL的设置问题
- C#编码规范
- This application has no explicit mapping for /error, so you are seeing this as a fallback
- Android 7.0系统 PopupWindow的bug
- python中的默认参数self
- c++强制类型转换:dynamic_cast、const_cast 、static_cast、reinterpret_cast
- 结合ZXing实现类似微信扫二维码放大摄像头
- wheelView自定义android日期时间选择器
- Aria2使用前端UI显示下载任务
- Verilog算法入门
- Log4j 2
- rem布局js设置