PopupWindow 用法小结

LayoutInflater mLayoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        view = mLayoutInflater.inflate(resId, null);

              //初始化PopupWindow
        mPopupWindow = new PopupWindow(view, 400, LayoutParams.WRAP_CONTENT);
        // mPopupWindow.setBackgroundDrawable(new
        // BitmapDrawable());//必须设置background才能消失
        mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_frame));
//        mPopupWindow.setOutsideTouchable(true);

        // 自定义动画
        // mPopupWindow.setAnimationStyle(R.style.PopupAnimation);
        // 使用系统动画
        mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
        mPopupWindow.update();
        mPopupWindow.setTouchable(true);
        mPopupWindow.setFocusable(true);
        
        if (!mPopupWindow.isShowing())
        {
            // mPopupWindow.showAsDropDown(view,0,0);
//            mPopupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
            mPopupWindow.showAsDropDown(view);
        }//显示 popupwindow
原文地址:https://www.cnblogs.com/lipeil/p/2651556.html