1、这里我直接给大家代码吧!// 将popupWindow显示在anchor下方
public void showAsDropDown(PopupWindow popupWindow, View anchor) {
if (Build.VERSION.SDK_INT < 24) {
popupWindow.showAsDropDown(anchor);
} else {
// 适配 android 7.0
int[] location = new int[2];
// 获取控件在屏幕的位置
anchor.getLocationOnScreen(location);
popupWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, 0, location[1] + anchor.getHeight());
}
}

2、if (Build.VERSION.SDK_INT < 24) {
mPopupWindow = new FixedPopupWindow(popView, ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
} else {
int[] location = new int[2];

3、 // 获取控件在屏幕的位置
anchor.getLocationOnScreen(location);
int screenHeight = getScreenHeightPixels(context);
mPopupWindow = new PopupWindow(popView, ViewGroup.LayoutParams.MATCH_PARENT,
screenHeight - (location[1] + anchor.getHeight()));
}

4、import android.graphics.Rect;
import android.os.Build;
import android.view.View;
import android.widget.PopupWindow;
/**
* Created by smart on 2018/5/15.
*/
public class FixedPopupWindow extends PopupWindow {
public FixedPopupWindow(View contentView, int width, int height){
super(contentView, width, height);

5、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; //屏幕高度减去 anchor 的 bottom
setHeight(h);// 重新设置PopupWindow高度
}
super.showAsDropDown(anchor);
}
...
}
