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
posted @ 2012-08-22 22:14  lipeil  阅读(1494)  评论(0编辑  收藏  举报