PopupWindow的show 7.0以后的适配,如下。
PopupWindow是在vTarget下方展示的,PopupWindow的上边对齐vTarget的上边,高度是vTarget的上边到屏幕底边。showAtLocation()方法第二个参数Gravity.TOP | Gravity.LEFT表示从屏幕上边show,后面是偏移量。
//这里还是有问题,继续往下看~~~~~~~~~~~~~~
if (mPopupWindow != null && !mPopupWindow.isShowing()) {
//7.0以下
if (Build.VERSION.SDK_INT < 24) {
mPopupWindow.showAsDropDown(vTarget, 0, -vTarget.getHeight());
} else {
Rect rect = new Rect();
vTabWholeLayout.getGlobalVisibleRect(rect);
int height = DeviceUtils.getScreenHeight() - rect.top + StatusBarUtil.getStatusBarHeight(mCon);
mPopupWindow.setHeight(height);
mPopupWindow.showAtLocation(vTarget, Gravity.TOP | Gravity.LEFT,
0, rect.top);
}
}
如下图,vTarget就是tab栏,点击右侧箭头 弹出PopupWindow。
更新!!!!!!!!!!!!!!!!!!
上面写的方法还是问题:如果打开或关闭底部虚拟导航栏 会影响popupWIdow的展示,如下
最终解决方案如下,只要重写showAsDropDown就可以了。
解决方法:
自定义PopupWindow时,重写showAsDropDown方法即可,如下。
@Override
public void showAsDropDown(View anchor, int xoff, int yoff) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
Rect rect = new Rect();
anchor.getWindowVisibleDisplayFrame(rect);
Rect outRect1 = new Rect();
mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect1);
int h = outRect1.height() - rect.bottom;
setHeight(h);
}
super.showAsDropDown(anchor, xoff, yoff);
}