10633

Question:
I have the following code, which tries to set the margin:
TableRow tr = new TableRow(this);
TableLayout.LayoutParams tableRowParams=
new TableLayout.LayoutParams
(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);
int leftMargin=20;
int topMargin=50;
int rightMargin=0;
int bottomMargin=50;
tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
tr.setLayoutParams(tableRowParams);
TextView name = new TextView(this);
name.setText(Html.fromHtml(venues.get(j).name + "<br><br>" + venues.get(j).getFullAddress()));
However this doesn't set the margin. What am I doing wrong here?
Answer1:Edit. Whoops, my bad, TableLayout.LayoutParams is fine. Use TableRow.LayoutParams on the children of the TableRow.
I just ran this code (which is, for the most part, your code) and the margin sets correctly
TableRow tr = new TableRow(this);
TableLayout.LayoutParams tableRowParams=
new TableLayout.LayoutParams
(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);
int leftMargin=100;
int topMargin=50;
int rightMargin=0;
int bottomMargin=50;
tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
tr.setLayoutParams(tableRowParams);
TextView tv = new TextView(this);
tv.setText("EXAMPLE ROW");
TableRow.LayoutParams textParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT);
tv.setLayoutParams(textParams);
tr.addView(tv);
tlayout.addView(tr);
Answer2:isn't it like so?
TableRow tr = new TableRow(Activity.this)
And I thik you'll nee a table for that row too.
Why not go for XML ?
<TableRow
android:id="@+id/tr1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TableRow>