这是系统级bug,需要我们自定义PopupWindow
public class PopView extends PopupWindow {
public PopView(Context context) {
super(context);
}
public PopView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public PopView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public PopView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public PopView() {
}
public PopView(View contentView) {
super(contentView);
}
public PopView(int width, int height) {
super(width, height);
}
public PopView(View contentView, int width, int height) {
super(contentView, width, height);
}
public PopView(View contentView, int width, int height, boolean focusable) {
super(contentView, width, height, focusable);
}
@Override
public void showAsDropDown(View anchor) {
if(Build.VERSION.SDK_INT >= 24) {
Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);
int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
setHeight(h);
}
super.showAsDropDown(anchor);
}
}