Estoy luchando con el horrible sistema de diseño de Android. Estoy tratando de obtener una tabla para llenar la pantalla (¿verdad?) Pero es ridículamente difícil.¿Cómo puedo obtener un TableLayout de Android para llenar la pantalla?
Yo tengo que trabajar de alguna manera en XML como esto:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent">
<TableRow android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1">
<Button android:text="A" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"/>
<Button android:text="B" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"/>
</TableRow>
<TableRow android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1">
<Button android:text="C" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"/>
<Button android:text="D" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"/>
</TableRow>
sin embargo no puedo conseguir que funcione en Java. Probé un millón de combinaciones de LayoutParams, pero nada funciona. Este es el mejor resultado que tengo que sólo llena el ancho de la pantalla, no la altura:
table = new TableLayout(this);
// Java. You suck.
TableLayout.LayoutParams lp = new TableLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
table.setLayoutParams(lp); // This line has no effect! WHYYYY?!
table.setStretchAllColumns(true);
for (int r = 0; r < 2; ++r)
{
TableRow row = new TableRow(this);
for (int c = 0; c < 2; ++c)
{
Button btn = new Button(this);
btn.setText("A");
row.addView(btn);
}
table.addView(row);
}
Obviamente la documentación de Android no es ninguna ayuda. ¿Alguien tiene alguna idea?
No creo que vaya a hacer que mucha gente se apresure a darle una respuesta con toda esa negatividad en su pregunta. –
Sí, lo sé. Es realmente frustrante cuando luchas por siglos con lo que debería ser una tarea simple. – Timmmm
+1 para el 'sistema de diseño retrasado de Android' –