如何禁用GridView不受PopupWindow滚动

问题描述 投票:0回答:1

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

showAsDropDown(查看锚点),如果屏幕上没有足够的空间显示*整个弹出窗口,此方法尝试查找父滚动*查看滚动。

我查看了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;
}
android gridview android-gridview
1个回答
0
投票

对于将来的读者,这是我解决了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);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.