Ich habe mit dem schrecklichen Layoutsystem von Android zu kämpfen. Ich versuche, einen Tisch zu bekommen, um den Bildschirm zu füllen (einfach richtig?), Aber es ist lächerlich schwer.Wie bekomme ich ein Android TableLayout, um den Bildschirm zu füllen?
Ich habe es irgendwie wie diese in XML zu arbeiten:
<?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>
Allerdings kann ich es nicht bekommen in Java zu arbeiten. Ich habe eine Million Kombinationen der LayoutParams ausprobiert, aber nichts funktioniert. Dies ist das beste Ergebnis, das ich habe, die nur die Breite des Bildschirms ausfüllt, nicht die Höhe:
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);
}
Offensichtlich ist die Android-Dokumentation ist keine Hilfe. Hat jemand Ideen?
Ich glaube nicht, dass Sie eine Menge Leute bekommen werden, die hetzen, um Ihnen eine Antwort mit all der Negativität in Ihrer Frage zu geben. –
Ja, ich weiß. Es ist einfach frustrierend, wenn man lange mit einer einfachen Aufgabe kämpft. – Timmmm
+1 für den 'verzögerte Layout Android system' –