PopUpWindow的使用方法及注意事项

来源:互联网 发布:君将哀而生之乎的翻译 编辑:程序博客网 时间:2024/05/07 10:02

PopUpWindow的使用方法及注意事项
在开发过程中PopUpWindow随处可见,其用法也相当简单,但要灵活应用还是需要有点功力的。
其中,pop主要用在弹窗等菜单选择中。
下面介绍其基本用法,很简单也还是贴出来看看:

private void showPopSelectPicWay() {        popWindow = null;        if (popWindow == null) {            //主要是解析布局            LayoutInflater inflater = (LayoutInflater) this                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);            View view = inflater.inflate(R.layout.pop_select_picway, null);            Button btnPhone = (Button) view.findViewById(R.id.btn_phone);            Button btnCamare = (Button) view.findViewById(R.id.btn_camare);            Button btnCancle = (Button) view.findViewById(R.id.btn_cancle);            btnPhone.setOnClickListener(new OnClickListener() {                @Override                public void onClick(View v) {                    popWindow.dismiss();                    selectPictureFromPhone();                }            });            //然后new一个            popWindow = new PopupWindow(view, LayoutParams.MATCH_PARENT,                    LayoutParams.MATCH_PARENT);            //设置属性            popWindow.setFocusable(true);            popWindow.setOutsideTouchable(true);            popWindow.setBackgroundDrawable(new BitmapDrawable());            //尤其是显示的位置            popWindow.showAtLocation(lin, Gravity.BOTTOM, 0, 0);        }    }

pop显示的位置分为以下几种方式:

  • popWindow.showAsDropDown(view);
  • popWindow.showAsDropDown(view, xoff, yoff);
  • popWindow.showAsDropDown(view, xoff, yoff, gravity);
  • popWindow.showAtLocation(view, gravity, xoff, yoff);
    具体问题用具体方法来把pop显示在具体位置上。
0 0
原创粉丝点击