api 25 PopupWindow显示不对问题

解决方法:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // Android 7.x,PopupWindow高度为match_parent,会出现兼容性问题,需要处理兼容性
int[] mLocation = new int[2];
stephenCommonTopTitleView.getTopTitleView().getLocationInWindow(mLocation);
int offsetY = mLocation[1] + stephenCommonTopTitleView.getTopTitleView().getHeight();
if (Build.VERSION.SDK_INT >= 25) { // Android 7.1中,PopupWindow高度为 match_parent 时,会占据整个屏幕
//故而需要在 Android 7.1上再做特殊处理
WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
int screenHeight = wm.getDefaultDisplay().getHeight();
centWinShare.setHeight(screenHeight - offsetY); // 重新设置 PopupWindow 的高度
}
centWinShare.showAtLocation(stephenCommonTopTitleView.getTopTitleView(), Gravity.NO_GRAVITY, 0, offsetY);
} else {
centWinShare.showAsDropDown(stephenCommonTopTitleView.getTopTitleView());
}

思路大概是这样
/*if (Build.VERSION.SDK_INT != 24) {
//只有24这个版本有问题,好像是源码的问题
showAsDropDown(view);
} else {
//7.0 showAsDropDown没卵子用 得这么写
int[] location = new int[2];
view.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
showAtLocation(view, Gravity.NO_GRAVITY, 0, y + view.getHeight());
//showAsDropDown(view, 0, marginTop);
}*/

猜你喜欢

转载自www.cnblogs.com/dubo-/p/9072767.html
25