指定位置弹出window

public class AddPopWindow extends PopupWindow{
    private View conentView;
    private  int w;
    private Context context;
    public AddPopWindow(final Activity context){
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        conentView = inflater.inflate(R.layout.title_right_add, null);
        this.context=context;
        int h = context.getWindowManager().getDefaultDisplay().getHeight();
         w = context.getWindowManager().getDefaultDisplay().getWidth();
        // 设置SelectPicPopupWindowView
        this.setContentView(conentView);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(w /3);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        // 刷新状态
        this.update();
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0000000000);
        // back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作
        this.setBackgroundDrawable(dw);
        // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
        // 设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.AnimationPreview);

    }

    public TextView getAddBaby(){
        return (TextView) conentView.findViewById(R.id.pop_add_baby);
    }

    public TextView getChangeBaby(){
        return (TextView) conentView.findViewById(R.id.pop_change_baby);
    }

    public TextView getDeleteBaby(){
        return (TextView) conentView.findViewById(R.id.pop_delete_baby);
    }

    /**
     * 显示popupWindow
     *
     * @param parent
     */
    public void showPopupWindow(View parent) {//parent是右上角的一个view
        if (!this.isShowing()) {
            // 以下拉方式显示popupwindow
            //this.showAsDropDown(parent, parent.getLayoutParams().width / 2, 5);
            int[] locations = new int[2];
            parent.getLocationOnScreen(locations);//获取view的坐标位置
	//显示在屏幕的2/3位置,减去自己的宽度(可以自己适当调位置,我这是3/4),在view下方加自己的高度
            this.showAtLocation(parent,
                    Gravity.NO_GRAVITY,w*2/3-parent.getMeasuredWidth()*3/4, locations[1] + parent.getMeasuredHeight()*3/4);

            //this.showAsDropDown(parent,w/3+ UtilTools.dip2px(context,200), locations[1] + parent.getMeasuredHeight());

        } else {
            this.dismiss();
        }
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值