PopupWindow底部弹出,底部UI被遮盖问题

     之前做项目的时候也碰到过PopupWindow从底部弹出,界面底部的UI有一部分被遮盖了。之前碰到这个问题的大多是类似华为手机之类的有虚拟按键的手机。可是这次我用来运行的机子是模拟机,也没有虚拟按键之类的东东。花了一点时间处理了,所以记录一下。

      

     首先:我先试试机子有没有NavigationBar,如果有我就按照以前的方法处理(判断手机是否有物理按钮,有则计算底部的NavigationBar高度,最后设置View边距)

public int getNavigationBarHeight() {

        boolean hasMenuKey = ViewConfiguration.get(this).hasPermanentMenuKey();
        boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
           if (!hasMenuKey && !hasBackKey) {
                Resources resources = getResources();
                int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
                //获取NavigationBar的高度 
                int height = resources.getDimensionPixelSize(resourceId);
                return height;
           }
           else{
                return 0;
          }
}

我运行了上面的代码,返回的是0再见再见再见  没有NavigationBar。好气啊。。怎么办怎么办怎么办!!!!!


     其次: 设置popupWindow.setClippingEnabled(false)

setClippingEnabled 这方法是什么啊。

官方的解释:

Allows the popup window to extend beyond the bounds of the screen. By default the window is clipped to the screen boundaries. Setting this to false will allow windows to be accurately positioned.  
If the popup is showing, calling this method will take effect only the next time the popup is shown or through a manual call to one of the update() methods.  
  
Parameters:  
enabled false if the window should be allowed to extend outside of the screen   

翻译:

允许弹出窗口扩展到屏幕的边界之外。默认情况下,窗口被剪切到屏幕边界。将其设置为false将使windows能够准确定位。

然后就变成了这样:

好气啊再见再见再见 这次好像是UI覆盖了返回键了。设置这个方法以后UI网上移动了一小部分,可是还是没有解决。。。

    

   最后:  检查代码

private void initPicPop() {
        if (mPopPicNotify == null) {
            DisplayMetrics dm = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(dm);
            mPopPicNotify = new PopupWindow(dm.widthPixels, dm.heightPixels);
            View popView = LayoutInflater.from(this).inflate(R.layout.layout_upload, null);
            TextView tvTackPic = (TextView) popView.findViewById(R.id.tv_photo);
            TextView tvAlbum = (TextView) popView.findViewById(R.id.tv_album);
            TextView tvCancel = (TextView) popView.findViewById(R.id.tv_cancel);
            mPopPicNotify.setContentView(popView);
            mPopPicNotify.setFocusable(true);
            mPopPicNotify.setBackgroundDrawable(new PaintDrawable(getResources().getColor(R.color.color_60000000)));
            mPopPicNotify.setClippingEnabled(false);
            mPopPicNotify.setOutsideTouchable(false);
            mPopPicNotify.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
            tvTackPic.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                        useCamera();
                    } else {
                        openPath();
                    }
                }
            });

            tvAlbum.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent albumIntent = new Intent(Intent.ACTION_PICK, null);
                    albumIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
                    startActivityForResult(albumIntent, REQUEST_ALBUM_OK);
                }
            });

            tvCancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mPopPicNotify.dismiss();
                }
            });
        }
        mPopPicNotify.showAtLocation(mRootView, Gravity.CENTER, 0, 0);

    }

看了几遍,也没有什么错误啊。最后试着重新创建PopupWindow

mPopPicNotify = new PopupWindow(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);

运行:

    

解决再见再见再见 

但是,原因还不是很清楚。

DisplayMetrics dm = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(dm);

mPopPicNotify = new PopupWindow(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
有什么区别,还有待我去学习。





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值