我对错误感到震惊:
java.lang.IllegalStateException: The specified child already has a parent. You must
call removeView() on the child's parent first.
单击发送按钮时,我想创建相对布局。
RelativeLayout rl = (RelativeLayout) findViewById(R.id.parentLayout);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//layoutParams.setMargins(0, 0, 25, 0);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.CENTER_IN_PARENT);
TextView tv= new TextView(ChatWithFriend.this);
tv.setId(layId);
tv.setText("data");
tv.setLayoutParams(lp);
rl.addView(tv);
setContentView(rl, layoutParams);
我的代码有什么问题吗?