PopUpWindow的使用方法及注意事项

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值