PopupWindow的show 7.0以后的适配

13 篇文章 2 订阅
8 篇文章 0 订阅

PopupWindow的show 7.0以后的适配,如下。
PopupWindow是在vTarget下方展示的,PopupWindow的上边对齐vTarget的上边,高度是vTarget的上边到屏幕底边。showAtLocation()方法第二个参数Gravity.TOP | Gravity.LEFT表示从屏幕上边show,后面是偏移量。

			//这里还是有问题,继续往下看~~~~~~~~~~~~~~
			if (mPopupWindow != null && !mPopupWindow.isShowing()) {
                    //7.0以下
                    if (Build.VERSION.SDK_INT < 24) {
                        mPopupWindow.showAsDropDown(vTarget, 0, -vTarget.getHeight());
                    } else {
                        Rect rect = new Rect();
                        vTabWholeLayout.getGlobalVisibleRect(rect);
                        int height = DeviceUtils.getScreenHeight() - rect.top + StatusBarUtil.getStatusBarHeight(mCon);
                        mPopupWindow.setHeight(height);
                        mPopupWindow.showAtLocation(vTarget, Gravity.TOP | Gravity.LEFT,
                                0, rect.top);
                    }

                }

如下图,vTarget就是tab栏,点击右侧箭头 弹出PopupWindow。
在这里插入图片描述在这里插入图片描述更新!!!!!!!!!!!!!!!!!!
上面写的方法还是问题:如果打开或关闭底部虚拟导航栏 会影响popupWIdow的展示,如下
在这里插入图片描述
最终解决方案如下,只要重写showAsDropDown就可以了。
解决方法
自定义PopupWindow时,重写showAsDropDown方法即可,如下。

    @Override
    public void showAsDropDown(View anchor, int xoff, int yoff) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
            Rect rect = new Rect();
            anchor.getWindowVisibleDisplayFrame(rect);
            Rect outRect1 = new Rect();
            mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect1);
            int h = outRect1.height() - rect.bottom;
            setHeight(h);
        }
        super.showAsDropDown(anchor, xoff, yoff);
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值