2012-03-15 29 views
12

está ahí y cualquier método para hacer tabla como HTML en Android donde puedo configurar el ancho de columna fila como lo hacemos en htmlCómo establecer Ancho de la mesa y el número de columnas en TableLayout en Android

<table > 
<tr><td style="width:'50%;"></td> 
    <td style="width:'50%;"></td> 
</tr> 
</table> 

<TableLayout 
      android:id="@+id/tableLayout1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:stretchColumns="3" > 
      <TableRow 
        android:id="@+id/tableRow1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" > 
      </TableRow> 
      <TableRow 
        android:id="@+id/tableRow1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" > 
      </TableRow> 
</TableLayout> 

Edición 1:

Para algo como HTML allí las obras de anchura porcentaje con respecto a su matriz

pero el peso introducido en Android funciona con respecto al tamaño de pantalla disponible para raíz.

Respuesta

22

Puede usar LinearLayout y el atributo de peso para lograr esto.

<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:weightSum="1.0"> 

Los elementos secundarios en sus filas pueden estar cada uno les da un peso como una porción de la suma (en porcentaje). Asegúrese de ajustar el layout_width a "0DP"

<Button 
android:layout_height="wrap_content" 
android:layout_width="0dp" 
android:layout_weight="0.5" /> 

<Button 
android:layout_height="wrap_content" 
android:layout_width="0dp" 
android:layout_weight="0.5" /> 

Compruebe hacia fuera esta pregunta anterior Linear Layout and weight in Android

16

El TableLayout tiene propiedades similares a LinearLayout. También hice algunas tweek sobre eso. Para decirlo mejor, mira mi código de muestra a continuación. Espero que sea útil.

<TableLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:stretchColumns="3" > 

     <TableRow 
      android:id="@+id/tableRow1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_weight="1"> 
      <TextView android:text="@string/test1" android:layout_weight="1"></TextView> 
      <TextView android:text="@string/test2" android:layout_weight="1"></TextView> 
      <TextView android:text="@string/test3" android:layout_weight="1"></TextView> 
     </TableRow> 

     <TableRow 
      android:id="@+id/tableRow2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_weight="1"> 
      <TextView android:text="@string/test1" android:layout_weight="1"></TextView> 
      <TextView android:text="@string/test2" android:layout_weight="1"></TextView> 
      <TextView android:text="@string/test3" android:layout_weight="1"></TextView> 
     </TableRow> 

     <TableRow 
      android:id="@+id/tableRow3" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_weight="1"> 
      <TextView android:text="@string/test1" android:layout_weight="1"></TextView> 
      <TextView android:text="@string/test2" android:layout_weight="1"></TextView> 
      <TextView android:text="@string/test3" android:layout_weight="1"></TextView> 
     </TableRow> 

    </TableLayout> 
+0

Los números de columna están basados ​​en cero, por lo que stretchColumns debe ser 2 – user648026

Cuestiones relacionadas