我有一个TableLayoutwith MATCH_PARENTforwidth和通过代码我添加一个TableRow,膨胀 a LinearLayout,所有有MATCH_PARENTfor width。如果我删除LinearLayout并直接将其添加TextView到TableRow它工作正常。但最后,TableRow具有WRAP_CONTENT宽度。我该怎么做?这是我的TableLayoutxml:
<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);