我尝试了很多东西,但没有得到任何解决方案,我在运行时设置文本,我需要根据文本大小弹出的宽度
LinearLayout viewGroup =(LinearLayout)((Activity)context)
.findViewById(R.id.popup);
LinearLayout viewGroup =(LinearLayout)((Activity)context)
.findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.popup_layout,viewGroup); title_tv = (TextView) layout.findViewById(R.id.popup_txt); title_tv.setText(title_P); PopupWindow popup = new PopupWindow(context); final float SCALE = layout.getResources().getDisplayMetrics().density; int mode = MeasureSpec.getMode(View.MeasureSpec.UNSPECIFIED); int measuredWidth = MeasureSpec.getSize(View.MeasureSpec.UNSPECIFIED); popup.setWidth(measuredWidth); popup.setHeight(60); popup.setContentView(layout); //popup.setWindowLayoutMode(); popup.setFocusable(true);