如何禁用 GridView 被 PopupWindow 滚动

How to disable the GridView from being scrolled by a PopupWindow

在我的 GridView 中,我会在用户长按时显示弹出窗口。但是根据文档,如果没有空间,Popupwindow 会尝试滚动视图的父级。 这就是我想避免的。

showAsDropDown(View anchor) 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.

我查看了 Popupwindow 文档,找到了以下方法来实现我的目标(避免滚动父级),但它不支持应用程序使用。

/**
 * Allow PopupWindow to scroll the anchor's parent to provide more room
 * for the popup. Enabled by default.
 *
 * @param enabled True to scroll the anchor's parent when more room is desired by the popup.
 */

@UnsupportedAppUsage
void setAllowScrollingAnchorParent(boolean enabled) {
    mAllowScrollingAnchorParent = enabled;
}

对于未来的读者,这是我解决 GridView 被 Popupwindow 强制滚动的方法。

我找不到在显示 Popupwindow 之前禁用 GridView 滚动的方法。所以我确保 Popupwindow 不会出现在底部边缘附近。

public void showDropDownMenu(View aView, PopupWindow aPopupWindow, int aMnuItemsNum){
    int[] loc = new int[2];
    aView.getLocationOnScreen(loc);

    int popHeight = (toPixels(getMnuItemHeightDip()) * aMnuItemsNum) + aView.getHeight();

    if(getResources().getDisplayMetrics().heightPixels - loc[1] > popHeight){
        aPopupWindow.showAsDropDown(aView);
    } else {
        aPopupWindow.showAsDropDown(aView, 0, - popHeight, Gravity.START | Gravity.TOP);
    }
}