window的showAsDropDown失效的问题

来源:互联网 发布:安装数据库失败日志 编辑:程序博客网 时间:2024/06/05 16:43

在使用Popupwindow的showAsDropDown的时候,有时候会在特定机型上无法正确显示(全屏显示了)。

目前的解决方案是如果需要全屏显示的popwindow,要计算出window的实际高度然后调用popupwindow的setHeight方法后再调用showAdDropDown即可。
获取PopupWindow的实际高度:

    public static void showPopwindow(Context context, PopupWindow popupWindow, View anchor) {        int[] locations = new int[2];        anchor.getLocationOnScreen(locations);        int screenHeight = context.getApplicationContext().getResources().getDisplayMetrics();     int height = screenHeight - anchor.getHeight() - locations[1];        popupWindow.setHeight(height);        popupWindow.showAsDropDown(anchor);    }

这里写图片描述

阅读全文
0 0
原创粉丝点击