我正在动态构建 TableLayout。而且我需要 TableRow 在某些列位置有间隙。
例如,我需要行在 3 和 5 位置有 ImageView,下一行在 1、2、4 位置有 ImageView。我尝试使用:
TableRow row1 = new TableRow(this);
row1.addView(new ImageView(this), 2);
row1.addView(new ImageView(this), 4);
mTable.addView(row1);
TableRow row2 = new TableRow(this);
row2.addView(new ImageView(this), 0);
row2.addView(new ImageView(this), 1);
row2.addView(new ImageView(this), 3);
mTable.addView(row2);
但我在运行时得到了 IndexOfBoundException 。
错误/AndroidRuntime(771): 原因: java.lang.IndexOutOfBoundsException: index=2 count=0
任何建议,将不胜感激。
谢谢你。