How do I set android:layout_weight on a text view programmatically?

Ortolig

New Member
I have a table layout in XML that does exactly what I want:\[code\]<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/evenrow"><TextView android:text="Check" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_weight="1"></TextView>\[/code\]I am trying to add the table row programmatically, but I can't seem to get the layout_weight set. Here is the java code:\[code\]TableRow.LayoutParams trlayout = new TableRow.LayoutParams (TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1);TableLayout.LayoutParams tablelayout = new TableLayout.LayoutParams (TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.FILL_PARENT);TableRow tr = new TableRow(this); tr.setLayoutParams(trlayout); TextView check = new TextView(this); check.setText(String.format("%5.2f", i)); tr.addView(check);\[/code\]I thought the 3rd param to new TableRow.LayoutParams was the default weight for the row's children, but it is not working.What am I missing?
 
Back
Top