I have LinearLayout inside TableRow. The LinearLayout get initiated in the code, this way:
LinearLayout mainRowLayout = new LinearLayout(this);
mainRowLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
TableRow tr = new TableRow(this);
tr.addView(mainRowLayout);
The problem is that the LinearLayout doesn't fill the parent (which is the TableRow). The attached images illustrates the problem, as shown in the Android's hirarchyViewer (The green rectangles are my marks).
"LinearLayout image"
Thanks.
When programmatically creating layouts, you need to give the parent container the layout instructions for the child.
// child element
LinearLayout mainRowLayout = new LinearLayout(this);
// parent element
TableRow tr = new TableRow(this);
// parent element's instructions (layout params for main row)
TableRow.LayoutParams lopForMainRow = new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
tr.addView(mainRowLayout, lopForMainRow);
Give it a go :]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With