我正在创建一个表单,用户输入他/她的地址,当用户保存表单时,流程会转到另一个活动,其中用户名称显示为其他。我正在使用TableLayout,并且在每个TableRow中,我都有一个TextView,它显示了可以用来删除条目的textview旁边的名称和ImageButton。现在,当我运行应用程序时,我只能看到布局中的TextView,ImageButton不可见。有人请帮助我,我哪里出错了?动态添加到表格中时ImageButton不可见
这里是我的代码部分:
if (requestCode == REC_INFO && resultCode == RESULT_OK && data != null) {
RecipientArray = (ArrayList<Person>) data
.getSerializableExtra("RecArray");
TableLayout tbl = new TableLayout(this);
TextView[] tv = new TextView[RecipientArray.size()];
ImageButton delete_btns[] = new ImageButton[RecipientArray.size()];
TableRow tr[] = new TableRow[RecipientArray.size()];
for (int i = 0; i < RecipientArray.size(); i++) {
tv[i] = new TextView(this);
tv[i].setBackgroundResource(R.drawable.fill_rece);
Person p = RecipientArray.get(i);
tv[i].setText(p.getName());
tv[i].setTextColor(Color.WHITE);
delete_btns[i] = new ImageButton(this);
delete_btns[i]
.setImageResource(R.drawable.ipad_postcare_landscape_from);
delete_btns[i].setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tr[i] = new TableRow(this);
tr[i].addView(tv[i]);
tr[i].addView(delete_btns[i]);
tbl.addView(tr[i]);
}
recs_layout.addView(tbl);//I add the TableLayout to a RelativeLayout
}
谢谢,用于响应,我曾通过将线所作的按钮可见加入delete_btns [I] .setLayoutParams(新的LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));然后我看到了你的答案和最后两行。他们没有任何区别。 – user2688158
如果你可以看看这个问题,并建议一个答案..这将有所帮助。 http://stackoverflow.com/questions/20754944/designing-the-tablelayout-which-has-to-be-added-dynamically-within-a-relativelay – user2688158