美文网首页
7.0系统PopupWindow Gravity.BOTTOM无

7.0系统PopupWindow Gravity.BOTTOM无

作者: 楷桐 | 来源:发表于2017-09-04 00:39 被阅读37次
     View view = LayoutInflater.from(context).inflate(layout, null);
     popupWindow = new PopupWindow(view, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    
     popupWindow.getContentView().measure(0, 0);
     popHeight = popupWindow.getContentView().getMeasuredHeight();
     getScreenHeight();
    
    
    private void getScreenHeight() {
            DisplayMetrics dm = new DisplayMetrics();
            ((Activity) v.getContext()).getWindowManager().getDefaultDisplay().getMetrics(dm); //v是Activity中的随意一View
            mWidthPixels = dm.widthPixels;
            mHeightPixels = dm.heightPixels;
        }
    
        @SuppressWarnings("deprecation")
        public void showAtLocation() {
            // 设置允许在外点击消失
            popupWindow.setOutsideTouchable(true);
            // 使其聚集
            popupWindow.setFocusable(true);
            // 设置弹出位置
            //popupWindow.showAtLocation(v, Gravity.BOTTOM, 0, 0);  //7.0以前的写法
            popupWindow.showAtLocation(v, Gravity.LEFT, 0, mHeightPixels - popHeight); //7.0后的
            //showDarkBg();
             // 刷新状态
            popupWindow.update();
        }
    

    相关文章

      网友评论

          本文标题:7.0系统PopupWindow Gravity.BOTTOM无

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