// 2、创建界面,显示数据 View view = View.inflate(context, R.layout.fileinfo, null); // 2.1给view添加监听器 initPopupWindowView(view, position); // 3、 popup = new PopupWindow(view, 400, LayoutParams.WRAP_CONTENT, true); popup.setBackgroundDrawable(getResources().getDrawable( R.drawable.popup_rectangle)); View decorView = BooksAndTableAvtivity.this.getWindow() .getDecorView(); popup.showAtLocation(decorView, Gravity.CENTER, 0, 0);
这里面需要注意的是:
1、LayoutParams是WindowManager中的内部类,
2、decorView是Activity中Window中的view tree的根节点。
3、效果是PopupWindow弹出的位置在整个Activity的中央位置。