Frage

I have empty Tablelayout in xml and adding tablerow programatically.

The row width is always behavies 'wrap_content' am I missing something.

tablelayout in layout.xml

<HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
        android:layout_width="fill_parent"
        android:layout_height="match_parent" >
<TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#ff0000">
            </TableLayout>
 </HorizontalScrollView>

Java code:

TableLayout mRestable= (TableLayout) findViewById(R.id.tableLayout1);
TableRow row = new TableRow(this);

TextView name_tw = new TextView(this);
name_tw.setTextSize((float) 16.8);
name_tw.setText(aName);
name_tw.setGravity(Gravity.LEFT);
name_tw.setPadding(10, 10, 10, 10);

if(aValue==null)
{
    name_tw.setBackgroundColor(0xffa09f9f);
    name_tw.setTextSize((float) 17.8);
    name_tw.setGravity( Gravity.CENTER);
    name_tw.setTypeface(Typeface.DEFAULT_BOLD);

}

row.addView(name_tw);        


mRestable.addView(row,new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
                        TableLayout.LayoutParams.WRAP_CONTENT)); 

how to set the row as 'fill_parent'

War es hilfreich?

Lösung

You have a HorizontalScrollView. What do you think, how wide a match_parent width child in it would be? match_parent in a scroll view is ignored for a reason.

If you want the table to fill the screen horizontally even if it does not need to scroll, set android:fillViewPort="true" on the HorizontalScrollView.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top