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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章