Установите ширину LinearLayout внутри TableRow на MATCH_PARENT

У меня есть TableLayout с MATCH_PARENT вместо width, и по коду я добавляю TableRow, что увеличивает LinearLayout, у всех MATCH_PARENT вместо width. Если я удалю LinearLayout и добавлю TextView к TableRow напрямую, все будет работать нормально. Но, наконец, TableRow имеет ширину WRAP_CONTENT. Как мне это сделать? Это мой 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>

Это LinearLayout для надувания:

<?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>

И код

// 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);

person rbrlnx    schedule 17.07.2012    source источник


Ответы (1)


Попробуйте изменить LayoutParams следующим образом:

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);
person user    schedule 17.07.2012
comment
Решение устанавливается android:stretchColumns=0 в tablelayout. Но спасибо за вашу помощь! - person rbrlnx; 17.07.2012
comment
@rbrlnx Да, мне не приходило в голову просто растянуть столбец. - person user; 17.07.2012