我想显示大小可变的弹出窗口。布局由 EditView 组成,我在显示弹出窗口之前在运行时设置了文本。我想要新布局的高度。我正在使用以下代码。任何人都可以帮助我解决我的错误和错误的方法来解决我的问题。
onsizechange 方法总是返回 yOld 和 yNew 零。
私人无效信息(字符串名称,字符串描述,视图v){
LayoutInflater layoutInflater = (LayoutInflater) getActivity() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View popupView = layoutInflater.inflate(R.layout.lo_popup_concerninfo, null, false); final LinearLayout ll = (LinearLayout) popupView.findViewById(R.id.lo_popup_concern_linearlayout); TextView tv_concernName = (TextView) popupView .findViewById(R.id.tv_concernName); final TextView tv_concernDesc = (TextView) popupView .findViewById(R.id.tv_concernDesc); Button btn_concernDone = (Button) popupView .findViewById(R.id.btn_concernDone); tv_concernName.setText(name); tv_concernDesc.setText(Description); ll.addView(new MyCustomView(getActivity().getApplicationContext())); Display display = getActivity().getWindowManager().getDefaultDisplay(); //popupView.measure(display.getWidth(), display.getHeight()); popupView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); System.out.println("view.getMeasuredWidth() " + popupView.getMeasuredWidth()); System.out.println("view.getMeasuredHeight() " + popupView.getMeasuredHeight()); final PopupWindow popup = new PopupWindow(popupView, display.getWidth() - 40, popupView.getMeasuredHeight() + finalHeight); System.out.println("view" + popup.getHeight()); popup.showAtLocation(v, Gravity.CENTER, 0, 10); popup.setFocusable(true); popup.update(); class MyCustomView extends View{ int viewWidth = 0; int viewHeight = 0; public MyCustomView(Context context) { super(context); System.out.println("ali1"); } @Override protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld){ super.onSizeChanged(xNew, yNew, xOld, yOld); viewWidth = xNew; viewHeight = yNew; System.out.println("xNew " + xNew); System.out.println("yNew " + yNew); System.out.println("xOld " + xOld); System.out.println("yOld " + yOld); } @Override protected void onDraw(Canvas canvas){ super.onDraw(canvas); String msg = "width: " + viewWidth + "height: " + viewHeight; System.out.println(msg); } }