【发布时间】:2020-03-19 17:55:41
【问题描述】:
我正在使用 TableLayout,其中每个表格行将包含三个单元格,每个单元格将显示一个图像。我希望每个图像视图/单元格的高度和宽度相等。问题是,默认情况下,tablerow 的高度会包裹到具有最大高度的 imageview/cell 的大小,因此行的高度不相等。
TableLayout tableLayout = (TableLayout) getActivity().findViewById(R.id.tableLayout);
TableRow.LayoutParams lp = new TableRow.LayoutParams(tableLayout.getWidth()/3, ViewGroup.LayoutParams.WRAP_CONTENT, 0.3f);
TableRow tableRow = new TableRow(getActivity().getApplicationContext());
lp.setMargins(1,1,1,1);
tableRow.setLayoutParams(lp);
imageView.setImageBitmap(b);
imageView.setLayoutParams(lp);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
tableRow.addView(imageView);
tableLayout.addView(tableRow);
这里是xml
<TableLayout
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*"
android:weightSum="1"
app:layout_constrainedHeight="false"
app:layout_constraintHeight_percent="0.5"
app:layout_constraintWidth_percent="1">
</TableLayout>
【问题讨论】:
标签: java android xml android-tablelayout