美文网首页
Android7.0上PopupWindow的showAsDro

Android7.0上PopupWindow的showAsDro

作者: xiny1024 | 来源:发表于2017-10-25 20:15 被阅读0次

在Android7.0和7.1.1手机上测试发现showAsDropDown(view)展示时发现会充满屏幕,而不是展示在view的下方

解决方法

方案一:使用showAtLocation方法,指定位置
方案二:重写showAsDropDown(view),如下

    @Override
    public void showAsDropDown(View anchor) {
        if (Build.VERSION.SDK_INT >= 24){
            Rect rect = new Rect();
            anchor.getGlobalVisibleRect(rect);
            int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
            setHeight(h);
        }
        super.showAsDropDown(anchor);
    }

相关文章

网友评论

      本文标题:Android7.0上PopupWindow的showAsDro

      本文链接:https://www.haomeiwen.com/subject/nnjcpxtx.html