popupwindow曾今遇到的坑

1,这几天在使用popupwindow的时候,遇到一个问题,使用showAsDropDown(View anchor)方法的时候居然无效,这只是针对7.0设备,其他手机以为正常,后来上网终于找到了问题所在,解决方案:

写一个popupwindow的子类,重写showAsDropDown(View anchor)

  @Override
    public void showAsDropDown(View anchor) {
        if (Build.VERSION.SDK_INT == 24) {
            Rect rect = new Rect();
            anchor.getGlobalVisibleRect(rect);
            //获取popupwindow的高度(屏幕的高度 - 锚点view的bottom的位置)
            int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
            setHeight(h);
        }
        super.showAsDropDown(anchor);
    }

构造方法PopupWindow(View contentView, int width, int height, boolean focusable),最后一个参数应为false
2.对于使用vitamio框架进行播放视频的时候,7.0设备上没有显示popupwindow,由于7.0似乎不支持Gravity.NO_GRAVITY属性:

 if (Build.VERSION.SDK_INT == 24) {//由于7.0似乎不支持Gravity.NO_GRAVITY属性
                    mWindow.showAtLocation(mAnchor, Gravity.TOP, 0, 0);
                } else {
                    mWindow.showAtLocation(mAnchor, Gravity.NO_GRAVITY, anchorRect.left, anchorRect.bottom);
                }

你可能感兴趣的:(----------高级UI)