0

I have a TableLayout with MATCH_PARENT for width and by code I add a TableRow, that inflates a LinearLayout, all have MATCH_PARENT for width. If I remove the LinearLayout and I add the TextView to the TableRow directly it works fine. But finally, TableRow has WRAP_CONTENT as width. How can I do it? This is my TableLayout xml:

  <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginBottom="7dp"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:layout_marginTop="7dp" >

    <TableLayout
                        android:id="@+id/tablaGremios"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentRight="true"
                        android:layout_below="@+id/titulopantalla"
                        android:background="@color/blanco" >
                    </TableLayout>

                </RelativeLayout>

This is the LinearLayout to inflate:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg_servicio"
    android:orientation="horizontal"
    android:weightSum="3" >

    <CheckBox
        android:id="@+id/cbGremioActivo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.01" />

    <View
        android:layout_width="1dip"
        android:layout_height="fill_parent"
        android:layout_marginRight="6dp"
        android:background="#e3e3e3" />

    <TextView
        android:id="@+id/tvGremio"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1.6"
        android:textSize="10sp" />

    <View
        android:layout_width="1dip"
        android:layout_height="fill_parent"
        android:layout_marginRight="6dp"
        android:background="#e3e3e3" />

    <TextView
        android:id="@+id/tvComentario"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1.4"
        android:textSize="10sp" />

</LinearLayout>

And the code

// Creo una fila por día en el objeto
                final TableRow tbRowGremio = new TableRow(contexto);

                tbRowGremio.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
                tbRowGremio.setId((numeroFila));
                LayoutInflater inflater = (LayoutInflater) contexto.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View lineaAPintar = inflater.inflate(R.layout.filalistagremios, null);
                lineaAPintar.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
                final CheckBox cbGremioActivo = (CheckBox) lineaAPintar.findViewById(R.id.cbGremioActivo);
                cbGremioActivo.setId(numeroFila);
                               TextView tvGremio = (TextView) lineaAPintar.findViewById(R.id.tvGremio);
                tvGremio.setText(gremioQueQuiereAnadir);
                TextView tvComentario = (TextView) lineaAPintar.findViewById(R.id.tvComentario);
                tvComentario.setText(etComentario.getText().toString());
                tbRowGremio.addView(lineaAPintar);
                tablaGremios.addView(tbRowGremio);
user
  • 86,916
  • 18
  • 197
  • 190
rbrlnx
  • 286
  • 7
  • 23

1 Answers1

0

Try to modify the LayoutParams like this:

final TableRow tbRowGremio = new TableRow(contexto);
tbRowGremio.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
tbRowGremio.setId((numeroFila));
LayoutInflater inflater = (LayoutInflater) contexto.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View lineaAPintar = inflater.inflate(R.layout.filalistagremios, null);
lineaAPintar.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
final CheckBox cbGremioActivo = (CheckBox) lineaAPintar.findViewById(R.id.cbGremioActivo);
cbGremioActivo.setId(numeroFila);
TextView tvGremio = (TextView) lineaAPintar.findViewById(R.id.tvGremio);
tvGremio.setText(gremioQueQuiereAnadir);
TextView tvComentario = (TextView) lineaAPintar.findViewById(R.id.tvComentario);
tvComentario.setText(etComentario.getText().toString());
tbRowGremio.addView(lineaAPintar);
tablaGremios.addView(tbRowGremio);
user
  • 86,916
  • 18
  • 197
  • 190