1.自定义popwindow重写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.弹出逻辑
if (Build.VERSION.SDK_INT < 24) {
mPopwindow.showAsDropDown(review);
} else {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N) {
int[] mLocation = new int[2];
review.getLocationInWindow(mLocation);
mPopwindow.showAtLocation(review, Gravity.NO_GRAVITY, 0, mLocation[1] + review.getHeight());
} else {
mPopwindow.showAsDropDown(review, 0, 0);
}
}