Search code examples
javaandroidnestedandroid-tablelayout

Size of programmatically created nested TableLayout in TableLayout doesn't match parent


I have a ScrollView in which there is a TableLayout that I dynamically populate with TableRows and TableLayouts which contains TableRows.

I want the TableRows of the nested TableLayouts to be displayed with the exact same way as the other TableRows.

Currently I get this result: enter image description here

The nested TableLayout is into the red circle. For example the first tableRow with the checkbox is the exact same object as the 3rd tableRow but the display is different. Probably the main Tablelayout treats differently other container layouts inside it. I do not use an additional layout inside the TableRows.

I included a layoutParameter when I added a child in both the main and the nested TableLayout but nothing changed.

table.addView(row,new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,1f));

Probably I have to add a different parameter but until now I could't find something that works. Any ideas?

P.S If my question is not clear enough please let me know what kind of additional information it is needed.


Solution

  • I managed to find a workaround. By setting the nested tableLayout

    table.setColumnStretchable(0, true);
    

    the nested tables stretch and fill the screen.

    But it is obvious that tableLayout is not the right View to use for such tasks. So I have to investigate more thing about inflating dynamically views in ListView. I will set the question as solved (cannot do it now,I have to wait for 2 days..)