【发布时间】:2018-10-11 07:11:53
【问题描述】:
这是一个简化的代码,用于在长按 GridView 项目时显示弹出窗口。
当最右边的项目调整为在屏幕内时弹出窗口。
但是当项目靠近屏幕底部时,弹出窗口会被裁剪(部分在屏幕外)。
如何解决这个问题?
PopupWindow mDropDownMenu= new PopupWindow(list, WRAP_CONTENT, WRAP_CONTENT);
mDropDownMenu.showAsDropDown(aView);
aView 是 GridView 项。
文档中提到了 showAsDropDown(View anchor)
* Display the content view in a popup window anchored to the bottom-left
* corner of the anchor view. If there is not enough room on screen to show
* the popup in its entirety, this method tries to find a parent scroll
* view to scroll. If no parent scroll view can be scrolled, the
* bottom-left corner of the popup is pinned at the top left corner of the
* anchor view.
*
但它总是固定在左下角,而不是左上角。
【问题讨论】:
-
能否提供截图以便更好理解。
-
我也有同样的问题。这里有一个旧帖子stackoverflow.com/questions/13115401/…,但没有给出可行的解决方案。
-
我也尝试过在 API 22 和 25 上使用 PopupWindowCompat。没有区别。问题依然存在。
-
如果你明确设置高度和宽度,它可以工作:PopupWindow(popupView, 100, 100).apply { setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) isTouchable = true isFocusable = true showAsDropDown(fragment_person_details__description) }
标签: android android-popupwindow