Question

I have a programmatically created created TableLayout with it's width set to match_parent. I am adding TableRows to it with 5 columns each. I have columns 1, 2, 4 & 5 all set to static widths. How do I set column 3 to fill the available space in the table so that the 5 columns total 100% width? (setting the TableRow width to match_parent does not do it)

Was it helpful?

Solution

Set a weight for the column 3 layout, so that it will fill the remaining space in the TableRow

    LinearLayout linearLayout = new LinearLayout(this);
    TableRow.LayoutParams params = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT,1f);
    linearLayout.setLayoutParams(params);
    tableRow.addView(linearLayout);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top