1、代码 适用于Android N+
/**
* 解决android N+ popupWindow 位移问题
* @param popupWindow
* @param view
* @param xoff x轴偏移
* @param yoff y轴偏移
*/
public static void showAsDropDown(final PopupWindow popupWindow, final View view, final int xoff, final int yoff) {
if (Build.VERSION.SDK_INT >= 24) {
Rect visibleFrame = new Rect();
view.getGlobalVisibleRect(visibleFrame);
int height = view.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom;
popupWindow.setHeight(height);
popupWindow.showAsDropDown(anchor, xoff, yoff);
} else {
popupWindow.showAsDropDown(anchor, xoff, yoff);
}
}