美文网首页
popupwindow 居中

popupwindow 居中

作者: 细雨么么 | 来源:发表于2022-05-18 12:52 被阅读0次

    public void showHintPopUpWindow(View view, Context context){

        View layoutView= LayoutInflater.from(context).inflate(R.layout.t_menu_item_terminallist,null);
        PopupWindow pw=new PopupWindow(layoutView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        TextView tv=layoutView.findViewById(R.id.log_item);
        tv.setPadding(4,4,4,4);
        pw.setOutsideTouchable(true);
        pw.setBackgroundDrawable(new BitmapDrawable());
        pw.setFocusable(true);
        pw.setContentView(layoutView);
        layoutView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        int popWidth=layoutView.getMeasuredWidth();
        int popHeight=layoutView.getMeasuredHeight();
        int [] location=new int[2];
        view.getLocationInWindow(location);
        pw.showAtLocation(view,Gravity.NO_GRAVITY,
                location[0]+ view.getWidth()/2-popWidth/2,
                    location[1]+popHeight
                );
    }

相关文章

网友评论

      本文标题:popupwindow 居中

      本文链接:https://www.haomeiwen.com/subject/bihaurtx.html