I'm trying to build a dynamic table in my Android application. I would like to have a 70% wide column and a 30% wide column.
If I do it with the layout xml using android:layout_weight I don't have any problem:
    <TableLayout
    android:id="@+id/TableLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="*"
    android:background="#ffffff" >
    <TableRow
        android:id="@+id/TableRow4"
        style="@style/RigaTabella"
        android:background="#d2ef7b" >
        <TextView
            android:id="@+id/TitoloSpesaTabella"
            style="@style/Titolo"
            android:layout_width="0px"
            android:layout_weight="0.7"
            android:background="#cdcdcd"
            android:text="@string/spesa" />
        <TextView
            android:id="@+id/TitoloCostoTabella"
            style="@style/Titolo"
            android:layout_width="0px"
            android:layout_weight="0.3"
            android:background="#ababab"
            android:text="@string/costo" />
    </TableRow>
</TableLayout>
This is what I obtain: https://i.stack.imgur.com/FLD91.jpg
(I used this gray background to show the real dimension of the two textView)
However if I try with this code:
TableLayout TableLayout = (TableLayout) findViewById(R.id.TableLayout);
    for (int i = 0; i < 10; i++) {
        TableRow Row = (TableRow) getLayoutInflater().inflate(R.layout.table_row_style, null);
        if (i % 2 == 0)
            Row.setBackgroundColor(Color.parseColor("#ffffff"));
        else
            Row.setBackgroundColor(Color.parseColor("#f1f1f1"));
        TextView tv = (TextView) getLayoutInflater().inflate(R.layout.testo_sx_style, null);
        tv.setText("Test Test");
        TextView tv2 = (TextView) getLayoutInflater().inflate(R.layout.testo_dx_style, null);
        tv2.setText("$ 1000");
        Row.addView(tv);
        Row.addView(tv2);
        TableLayout.addView(Row);
    }
where testo_sx_style.xml is:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="0px"
    android:layout_height="wrap_content"
    android:layout_weight="0.7"
    android:gravity="left"
    android:textSize="13sp"
    android:textColor="#161616"
    android:typeface="monospace"
    android:background="#cdcdcd"
/>
and where testo_dx_style.xml is:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="0px"
    android:layout_height="wrap_content"
    android:layout_weight="0.3"
    android:gravity="left"
    android:textSize="13sp"
    android:textColor="#161616"
    android:typeface="monospace"
    android:background="#ababab"
/>
I obtain this: https://i.stack.imgur.com/MIvwH.png
I really don't know what it's wrong. I also tried, for example, to set in testo_sx_style.xml the layout_width to 100px but it doesn't change anything. It seems that some properties aren't applied to my code.
Anyone know what is the error? Thanks in advance.
Have a good day :)
p.s. Sorry for my English
 
     
    