【发布时间】:2019-09-09 07:25:54
【问题描述】:
我在我的应用程序中以编程方式添加了一个表格布局。第一列由 imageviews 和第二列 textviews 组成,如下面的代码所示
for (int i = 0; i <23; i++) {
TableRow row= new TableRow(this);
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT);
row.setLayoutParams(lp);
tv = new TextView(this);
tv.setText(array[i]);
ImageView image65 = new ImageView(this);
image65.setBackgroundResource(R.drawable.ic_no);
row.addView(tv,1);
row.addView(image65,0);
ll.addView(row,i);
}
一切都很好,除了我想在 sp 中指定图像视图的宽度和长度。如何在行的布局婴儿车旁边为图像视图添加布局婴儿车?我尝试了以下方法,但没有成功。
for (int i = 0; i <23; i++) {
TableRow row= new TableRow(this);
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT);
row.setLayoutParams(lp);
TableRow.LayoutParams lp2 = new TableRow.LayoutParams(customwidth,customheight);
tv = new TextView(this);
tv.setText(array[i]);
ImageView image65 = new ImageView(this);
image65.setBackgroundResource(R.drawable.ic_no);
image65.setLayoutParams(lp2);
row.addView(tv,1);
row.addView(image65,0);
ll.addView(row,i);
}
【问题讨论】:
标签: java android user-interface tablelayout android-tablelayout