Android 7.0以上(包含8.0), popupWindow弹窗位置异常, 解决方案

本文转载地址:https://blog.csdn.net/zhihui_520/article/details/79097161

终极解决方案(7.0, 7.1, 8.0)
 

/**
 *
 * @param pw     popupWindow
 * @param anchor v
 * @param xoff   x轴偏移
 * @param yoff   y轴偏移
 */
public static void showAsDropDown(final PopupWindow pw, final View anchor, final int xoff, final int yoff) {
    if (Build.VERSION.SDK_INT >= 24) {
        Rect visibleFrame = new Rect();
        anchor.getGlobalVisibleRect(visibleFrame);
        int height = anchor.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom;
        pw.setHeight(height);
        pw.showAsDropDown(anchor, xoff, yoff);
    } else {
        pw.showAsDropDown(anchor, xoff, yoff);
    }
}

 

 
发布了123 篇原创文章 · 获赞 45 · 访问量 21万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章