解决方案: 重写PopWindow的showAsDropDown()方法.
详细步骤
1.新建类MyPopWindow,继承PopupWindow.
2.重写showAsDropDown()方法.
public class MyPopWindow extends PopupWindow {
public MyPopWindow(View contentView, int width, int height) {
super(contentView,width,height);
}
@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);
}
@Override
public void showAsDropDown(View anchor, int xoff, int yoff) {
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, xoff, yoff);
}
}
3.把使用PopupWindow的地方改为自己写的MyPopWindow.