Android开发Android知识分享

Android开发:PopupWindow优化

2018-11-20  本文已影响2人  徐影魔

CompatPopupWindow

github

核心代码

@Override
    public void showAsDropDown(View anchor, int xoff, int yoff, int gravity) {
        int adjustYoff = adjustYoff(anchor, yoff);
        super.showAsDropDown(anchor, xoff, adjustYoff, gravity);
    }

    private int adjustYoff(View anchor, int yoff) {
        if (anchor == null) {
            return 0;
        }
        anchor.getLocationInWindow(location);
        int availableHeight = UtilsSize.getScreenHeight(anchor.getContext()) - location[1] - anchor.getHeight();
        int minWidowHeight = getMinWidowHeight();
        if (availableHeight < minWidowHeight && minWidowHeight != -1) {
            yoff -= minWidowHeight;
            if (useAnimStyle) {
                setAnimationStyle(R.style.AnimStyle_Bottom);
            }
        } else {
            if (useAnimStyle) {
                setAnimationStyle(R.style.AnimStyle);
            }
        }
        return yoff;
    }
上一篇 下一篇

猜你喜欢

热点阅读