您的位置:首页 > 移动开发 > Android开发

PopWindow Android 7.0 位置显示不准确解决办法

2017-02-23 15:34 435 查看
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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: