public void show(){
//显示位置 一开始写的
//popupWindow.showAsDropDown(relayView);
//后来改的
showAsDropDown(popupWindow,relayView,0,relayView.getHeight());
popupWindow.update();
}
public static void showAsDropDown(final PopupWindow pw, final View anchor, final int xoff, final int yoff) {
if (Build.VERSION.SDK_INT >= 24) {
Rect visibleFrame = new Rect();
anchor.getGlobalVisibleRect(visibleFrame);
int height = anchor.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom;
pw.setHeight(height);
pw.showAsDropDown(anchor, xoff, yoff);
} else {
pw.showAsDropDown(anchor, 0, 0);
}
}
出处忘记了,但是亲测可用,做个记录。侵权即删
本文分享了在不同Android SDK版本下,通过调整PopupWindow显示位置的代码实现方法。介绍了如何根据设备屏幕高度和目标视图的位置来更新PopupWindow的高度,以确保其正确显示在目标视图下方,同时避免超出屏幕范围。
471

被折叠的 条评论
为什么被折叠?



