我正在从SOAP服务读取数据,然后使用该数据从本地加载res文件夹中的图像。我正在使用循环,因为总会有六个图像被加载。这是我的代码:
final TableLayout tblLay = (TableLayout)findViewById(R.id.lottotl);
final LayoutParams params = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
for(int i=2;i<9;i++) {
final ImageView image = new ImageView(LastDraw.this);
image.setLayoutParams(trparams);
image.setMaxHeight(20);
image.setMaxWidth(20);
String imgName = "img_" + split[i].substring(split[i].indexOf("=") + 1);
int id = getResources().getIdentifier(imgName, "drawable", getPackageName());
image.setImageResource(id);
row2.setLayoutParams(params);
row2.addView(image);
}
tblLay.addView(row2);
我遇到的问题是第一张图像和连续图像之间存在间隙。
看起来像这样(每个数字代表一个图像):
1 ......... 23456
我在想它与tablelayout中行的布局有关,我可能错了。
谢谢
任何?
答案 0 :(得分:0)
想出来......觉得有点愚蠢,但是我学到了一些东西!我将textview加载到第一行,然后将imageview加载到第二行。 textview位于第一列,其宽度使第一列拉伸......这就是为什么存在差距。