1.重写popupWindow 的showAsDropDown()方法:
@Override
public void showAsDropDown(View anchor) {
if(Build.VERSION.SDK_INT >= 24) {
Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);
int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
setHeight(h);
}
super.showAsDropDown(anchor);
2.初始化popupWindow时候高度不要MATCH_PARENT
int[] location = new int[2];
view.getLocationOnScreen(location);//view是在xx控件下方的xx
int y = location[1];
int popHeight = ScreenUtils.getScreenHeight(activity) - y;
CustomPopupWindow myPop=new CustomPopupWindow(contentView, LinearLayoutCompat.LayoutParams.MATCH_PARENT, popHeight);
这样子7.0以上的就适配好了