【发布时间】:2011-04-19 08:24:02
【问题描述】:
我想动态地将行添加到表格布局中。这是我的代码。
TableRow tableRow = null;
TextView textView = null;
ImageView imageView = null;
TableLayout tableLayout = (TableLayout)findViewById(R.id.tableLayout);
RelativeLayout relativeLayout = null;
for (String string: listOfStrings) {
tableRow = new TableRow(this);
relativeLayout = (RelativeLayout) View.inflate(this,
R.layout.row, null);
textView = (TextView) relativeLayout.getChildAt(0);
textView.setText(string);
imageView= (ImageView) relativeLayout.getChildAt(1);
imageView.setBackgroundColor(R.color.blue);
tableRow.addView(relativeLayout);
tableLayout.addView(tableRow);
}
我创建了一个宽度为 fill_parent 的行布局,最左侧的 textView 和最右侧的 imageView。然而,当我运行这个程序时,行宽出现 wrap_content 而不是 fill_parent 与图像重叠文本。请帮忙。谢谢
【问题讨论】:
标签: android