搜索
热搜: 活动 交友 discuz
查看: 3910|回复: 0
打印 上一主题 下一主题

Android7.0 7.1 popupwindow showAsDropDown 显示位置异常解决办法

[复制链接]

160

主题

165

帖子

814

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
814
跳转到指定楼层
楼主
发表于 2018-1-11 10:06:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1.     public static void showAsDropDown(PopupWindow pw, View anchor, int xoff, int yoff) {
  2.         if (Build.VERSION.SDK_INT >= 24) {
  3.             int[] location = new int[2];
  4.             anchor.getLocationOnScreen(location);
  5.             // 7.1 版本处理
  6.             if (Build.VERSION.SDK_INT == 25) {
  7.                 //【note!】Gets the screen height without the virtual key
  8.                 WindowManager wm = (WindowManager) pw.getContentView().getContext().getSystemService(Context.WINDOW_SERVICE);
  9.                 int screenHeight = wm.getDefaultDisplay().getHeight();
  10.                 /*
  11.                 /*
  12.                  * PopupWindow height for match_parent,
  13.                  * will occupy the entire screen, it needs to do special treatment in Android 7.1
  14.                 */
  15.                 pw.setHeight(screenHeight - location[1] - anchor.getHeight() - yoff);
  16.             }
  17.             pw.showAtLocation(anchor, Gravity.NO_GRAVITY, xoff, location[1] + anchor.getHeight() + yoff);
  18.         } else {
  19.             pw.showAsDropDown(anchor, xoff, yoff);
  20.         }
  21.     }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|安卓论坛  

GMT+8, 2024-5-6 15:33 , Processed in 0.058656 second(s), 24 queries .

Powered by Discuz! X3.2

© 2001-2013 Design S!|ƽ̶

快速回复 返回顶部 返回列表