之前有段代码的业务实现是弹出一个PopupWindow,覆盖除了标题栏外的区域。
原始代码:
int[] location = new int[2];
scrollView.getLocationOnScreen(location);
setHeight(context.getResources().getDisplayMetrics().heightPixels - location[1]);
showAtLocation(view, Gravity.NO_GRAVITY, 0, location[1]);
之后突然发现高度显示有问题,搞了半天才发现是刘海屏的适配问题,一开始还以为是Android版本适配的问题。。。
修改后的代码:
setHeight(scrollView.getHeight());
showAtLocation(view, Gravity.BOTTOM, 0, 0);
刘海屏的手机调用getLocationonscreen()方法得到的偏移量是不准确的,但是从底部算高度是准确的。