Android 不同版本7.0以下,7.0,7.1以上 popwindow展示位置控制分享
来源:互联网 发布:激战2母夏尔捏脸数据 编辑:程序博客网 时间:2024/06/06 05:36
今天给大家分享下Android不同版本下popwindow展示位置控制;公司的项目在进行云测后发现了popwindow适配出现问题;
下面先给大家展示下我之前有问题代码:
if (Build.VERSION.SDK_INT >=24) { // 系统7.0以上, popupwindow底层修改了Gravity属性 Gravity.START // | Gravity.TOP int[] a = new int[2]; anchor.getLocationOnScreen(a); showAtLocation(activityWeakReference.get().getWindow().getDecorView(), Gravity.NO_GRAVITY, 0, a[1] + anchor.getHeight());} else { CardsListPanel.super.showAsDropDown(anchor);}
上面代码的意思就是在Android系统7.0以下时就调用popwindow.showAsDropDown(anchor)方法;
7.0以上的就调用:
showAtLocation(activityWeakReference.get().getWindow().getDecorView(), Gravity.NO_GRAVITY, 0, a[1] + anchor.getHeight());设置显示的样式,以及popwindow展示的起始位置anchor到屏幕的高度+anchor自身的高度;
我们看下效果图:
7.0以下和7.0的界面是正常的,可是7.1以上的就尴尬了;
7.1以上的界面:
界面上面的搜索框直接被遮盖住了;查了百度,上面千篇一律都是说要像上面那样写;
搞了半天才查到可行的方法,这里大家分享下,把代码改成下面这样:
if (Build.VERSION.SDK_INT >=24) { // 系统7.0以上, popupwindow底层修改了Gravity属性 Gravity.START // | Gravity.TOP int[] a = new int[2]; anchor.getLocationOnScreen(a); // 7.1以上 版本处理 if (Build.VERSION.SDK_INT >= 25) { //【note!】Gets the screen height without the virtual key WindowManager wm = (WindowManager) getContentView().getContext().getSystemService(activity.WINDOW_SERVICE); int screenHeight = wm.getDefaultDisplay().getHeight(); /* * PopupWindow height for match_parent, * will occupy the entire screen, it needs to do special treatment in Android 7.1 */ setHeight(screenHeight - a[1] - anchor.getHeight()); } showAtLocation(activityWeakReference.get().getWindow().getDecorView(), Gravity.NO_GRAVITY, 0, a[1] + anchor.getHeight());} else { CardsListPanel.super.showAsDropDown(anchor);}大家看到差别在哪里了吗?代码意思改为,7.0以上改成showAtLocation()方法去展示位置,但7.1以上版本要先重新设置popwindow的高度,之后再设置展示的位置;到这里就ok了,我试了下7.1.1和8.0的手机都没问题了;展示效果都是好的。
希望本文对大家有所帮助!!!
阅读全文
0 0
- Android 不同版本7.0以下,7.0,7.1以上 popwindow展示位置控制分享
- Android 7.0 7.1 Popwindow显示位置异常处理方法
- popwindow 在android 7.0位置错误
- 华为手机7.0以上华为7.0上popwindow位置显示错乱,飘
- PopWindow Android 7.0 位置显示不准确解决办法
- android popwindow的显示位置
- android popwindow 位置和动画
- shape 画圆角图片,圆角位置在3.0版本以下和3.0以上取值相反的解决办法
- Android友盟新浪分享5.0以下版本报错SSLSocket
- Popupwindow在Android 7.0以上系统位置显示不对的解决办法
- 分享一下方法 用SQL2005以上版本
- android 4.4版本以上系统相册图片返回URI的不同处理
- Popwindow与Dialog不同方式展示底部动画弹起弹窗
- apache-tomcat-7.0.*以上版本配置
- ios6以上版本的旋转控制
- Android N上Popwindow显示位置不正确问题
- Android N上Popwindow显示位置不正确问题
- PopWindow的showAsDropDown在7.0手机上显示位置错乱问题
- 大数据分析平台搭建教程:基于Apache Zeppelin Notebook和R的交互式数据科学
- 无序数组找出其中的第K大的数
- 从数据库中查询邮箱,然后发送多人邮件
- 系统调用
- 邻接矩阵和弗洛伊德
- Android 不同版本7.0以下,7.0,7.1以上 popwindow展示位置控制分享
- openSMILE安装教程
- iOS和android的屏幕适配
- DEv Grid打印
- 如何在github上搭建个人博客
- 浏览器内核引擎分类归纳
- 错误: 找不到或无法加载主类 Welcome
- AtomicBoolean使用方法
- Php中类的继承,封装,多态