我遇到了问题,我的图像没有在我以编程方式创建的Tablelayout中正确缩小。
This is what I'm currently getting
这是我的代码:
final TableLayout grd_overview = (TableLayout)this.findViewById(R.id.tbl_overview);
grd_overview.setShrinkAllColumns(true);
Integer[] mThumbIds = { R.drawable.memory_1, R.drawable.memory_2, R.drawable.memory_1, R.drawable.memory_2, R.drawable.memory_1, R.drawable.memory_2, R.drawable.memory_2, R.drawable.memory_1, R.drawable.memory_2, R.drawable.memory_1,R.drawable.memory_2, R.drawable.memory_1, R.drawable.memory_1, R.drawable.memory_2, R.drawable.memory_1, R.drawable.memory_2, R.drawable.memory_1, R.drawable.memory_2, R.drawable.memory_2, R.drawable.memory_1, R.drawable.memory_2, R.drawable.memory_1, R.drawable.memory_2, R.drawable.memory_1, R.drawable.memory_1, R.drawable.memory_2, R.drawable.memory_1, R.drawable.memory_2, R.drawable.memory_1, R.drawable.memory_2, R.drawable.memory_2, R.drawable.memory_1, R.drawable.memory_2, R.drawable.memory_1, R.drawable.memory_2, R.drawable.memory_1};
int x = 0;
for (int j = 0; j <= 5; j++) {
TableRow tr = new TableRow(this);
tr.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
for (int i = 0; i <= 5; i++) {
ImageView iv = new ImageView(this);
iv.setImageResource(mThumbIds[x]);
tr.addView(iv);
x++;
}
grd_overview.addView(tr);
}
XML:
<TableLayout
android:id="@+id/tbl_overview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
我不知道如何缩小所有ImageView
完美匹配的行。底部屏幕截图上的图像比它们应该的要小。
答案 0 :(得分:0)
您可以在ImageView
周期内初始化每个for
后添加以下代码行:
iv.setScaleType(ScaleType.FIT_CENTER);
或者选择最适合您需求的缩放类型。
您可以阅读有关ScaleTypes here以及scaling matrice algorithms的更多信息,例如:这是FIT_CENTER
的作用。