I have a TableLayout
with multiple TableRow
views inside it. I wish to specify the height of the row programatically. E.g.
int rowHeight = calculateRowHeight();
TableLayout tableLayout = new TableLayout(activity);
TableRow tableRow = buildTableRow();
TableLayout.LayoutParams rowLp = new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT, rowHeight);
tableLayout.addView(tableRow, rowLp);
But this isn't working and is defaulting to WRAP_CONTENT. Digging around in the Android source code, I see this in TableLayout
(triggered by the onMeasure() method):
private void findLargestCells(int widthMeasureSpec) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child instanceof TableRow) {
final TableRow row = (TableRow) child;
// forces the row's height
final ViewGroup.LayoutParams layoutParams = row.getLayoutParams();
layoutParams.height = LayoutParams.WRAP_CONTENT;
Seems like any attempt to set the row height will be overridden by the TableLayout. Anyone know a way around this?
findLargestCells()
) in the TableLayout source code resets the height of the ViewGroup.LayoutParams to WRAP_CONTENT regardless of what I specify. – Hent