解决方案:
用
if (Build.VERSION.SDK_INT < 24) {
popupWindow.showAsDropDown(view);
} else {
int[] location = new int[2];
view.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, 0, y + view.getHeight());
}
替换:
popupWindow.showAsDropDown(view);
在部分机型上上述方法无效,可以尝试另一种方案:
if (Build.VERSION.SDK_INT > 24) {
Rect rect = new Rect();
mView.getGlobalVisibleRect(rect);
int h = mView.getResources().getDisplayMetrics().heightPixels - rect.bottom;
popWindow.setHeight(h);
}
categoryWindow.showAsDropDown(categoryView, 0, PhoneUtils.dp2px(getContext(), 0.5));