I think that there is possible bug in TableLayout SDK 1.0 rc2 when
constructing table from code. It seams that the weight  or height
attribute is not respected when rendering the layout.

The XML view creates a table with row at the top and row at the bottom
of the screen  which is what supposed to happen, so I created this
same table via code but the results are not what were expected. Maybe
I am missing something but it seams OK, all LayoutParams  are this
same.


Sample Code
[code]
private View buildTableViewFromSource(){
                TableRow.LayoutParams pTable=new TableRow.LayoutParams
(TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.FILL_PARENT);

                TableLayout table = new TableLayout(context);
                table.setBackgroundColor(Color.RED);
                table.setLayoutParams(pTable);


                TableRow rowTop = new TableRow(context);

                TableRow.LayoutParams pRowTop=new TableRow.LayoutParams
(TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.FILL_PARENT);
                pRowTop.height=TableRow.LayoutParams.FILL_PARENT;
                pRowTop.width=TableRow.LayoutParams.FILL_PARENT;
                pRowTop.weight=1;

                rowTop.setBackgroundColor(Color.BLUE);

                TextView txt=new TextView(context);
                txt.setText("Top Content");

                rowTop.addView(txt, pRowTop);

                TableRow rowBottom=new TableRow(context);
                rowBottom.setBackgroundColor(Color.GREEN);

                TextView txtBottom=new TextView(context);
                txtBottom.setText("Bottom Content");

                TableRow.LayoutParams pRowBottom=new TableRow.LayoutParams
(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT);
                pRowBottom.height=TableRow.LayoutParams.WRAP_CONTENT;
                pRowBottom.width=TableRow.LayoutParams.FILL_PARENT;
                pRowBottom.weight=0;

                rowBottom.addView(txtBottom);

                table.addView(rowTop, pRowTop);
                table.addView(rowBottom, pRowBottom);

                return table;
        }


        private View buildTableViewFromXML(){
                LayoutInflater inflater=(LayoutInflater) getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
                LinearLayout layout=(LinearLayout) 
inflater.inflate(R.layout.table,
null);
                TableLayout table=(TableLayout) layout.findViewById
(R.id.tableBottomLayout);
                layout.removeView(table);

                TableRow rowContent=(TableRow)table.findViewById(R.id.rowTop);

                TextView txt=new TextView(context);
                txt.setText("Top Content");
                rowContent.addView(txt);

                TableRow rowTabs=(TableRow)table.findViewById(R.id.rowBottom);


                TextView txtBottom=new TextView(context);
                txtBottom.setText("Bottom Content");
                rowTabs.addView(txtBottom);

                return table;
        }
[code]

[code]
<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/
android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/tableBottomLayout">

        <TableRow android:id="@+id/rowTop"
                android:layout_width="wrap_content" android:layout_weight="1"
                android:layout_height="fill_parent">

        </TableRow>

        <TableRow android:id="@+id/rowBottom"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:layout_weight="0">
                <!--
                        <TextView android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="HEllo"></TextView>
                -->
        </TableRow>

</TableLayout>
[code]

Any suggestions , if anyone else can confirm this I will post this as
a bug.

Thanks
Greg
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to