当前位置: 代码迷 >> 综合 >> Android7.0上PopupWindow的showAsDropDown位置问题
  详细解决方案

Android7.0上PopupWindow的showAsDropDown位置问题

热度:44   发布时间:2023-12-14 01:55:13.0

    Rect rect = new Rect();anchor.getGlobalVisibleRect(rect);int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;setHeight(h);


不判断24 统统加上,可以解决弹出位置不在正下方的问题

问题说明

我的popupWindow是用来展示listView的,近期在Android7.0手机上测试发现showAsDropDown(view)展示时发现会充满屏幕,而不是展示在view的下方,测试发现在7.0以下和7.1系统下都没有类似问题。

问题解决

重写showAsDropDown(view),如下:

@Overridepublic void showAsDropDown(View anchor) {if(Build.VERSION.SDK_INT == 24) {Rect rect = new Rect();anchor.getGlobalVisibleRect(rect);int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;setHeight(h);}super.showAsDropDown(anchor);}
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  相关解决方案