popWindow 在Android7.0上的显示位置不管怎么设置都在屏幕的顶部,这是7.0的bug,已在7.1修复,但是7.0还是需要我们自己解决的,方法如下:
@Override
public void showAsDropDown(View anchorView, int xoff, int yoff) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N) {
int[] a = new int[2];
anchorView.getLocationInWindow(a);
showAtLocation(anchorView, Gravity.NO_GRAVITY, xoff, a[1] + anchorView.getHeight() + yoff);
} else {
super.showAsDropDown(anchorView, xoff, yoff);
}
}
@Override
public void showAsDropDown(View anchorView) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N) {
int[] a = new int[2];
anchorView.getLocationInWindow(a);
showAtLocation(anchorView, Gravity.NO_GRAVITY, 0, a[1] + anchorView.getHeight() + 0);
} else {
super.showAsDropDown(anchorView);
}
}
本文针对Android7.0中PopWindow显示位置固定的Bug提供了解决方案。通过判断系统版本并调整PopWindow的位置参数,使得在Android7.0上也能正确显示PopWindow的位置。

1万+

被折叠的 条评论
为什么被折叠?



