Android弹出窗口PopuWindow

1、

/**

* 弹出页面

* @return
*/
@SuppressLint("InflateParams")
public PopupWindow mPopupWindow() {
@SuppressWarnings("static-access")
LayoutInflater mInflater = (LayoutInflater) getActivity().getSystemService(getActivity().LAYOUT_INFLATER_SERVICE);
ViewGroup menuView = (ViewGroup) mInflater.inflate(R.layout.popup_more1, null, true);//获得自定义布局
final PopupWindow pw = new PopupWindow(menuView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
pw.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
pw.setOutsideTouchable(true);//设置弹出窗体的其他位置是否可以点击 然后弹出窗消失
pw.setFocusable(true);
pw.update();
// 获取屏幕宽度
WindowManager wm = getActivity().getWindowManager();
width = wm.getDefaultDisplay().getWidth();

height = wm.getDefaultDisplay().getHeight();

//处理弹出窗的单击事件

ll_bywoman = (LinearLayout) menuView.findViewById(R.id.ll_bywoman);


// PopupWindow中的控件,


ll_bywoman.setOnClickListener(new View.OnClickListener() {


@Override
public void onClick(View v) {

System.out.println("弹出窗单击事件");
pw.dismiss();//消失弹出窗
}
});


return pw;

}


2、弹出窗的位置设置

      有几种方式

mPopupWindow().showAsDropDown(anchor);
mPopupWindow().showAsDropDown(anchor, xoff, yoff);
mPopupWindow().showAtLocation(parent, gravity, x, y);

你可能感兴趣的:(Android弹出窗口PopuWindow)