B
BFK
Fortgeschrittenes Mitglied
- 11
Hallo,
ich versuche ein TableLayout dynamisch (also per Code) zu erstellen.
Das Table Layout soll genau so aussehen..:
Mein Code sieht bis jetzt so aus..:
So wie der Code-Abschnitt so steht, wird überhauot nichts erstellt.
Ich glaube auch, dass es an das "setLayoutParams" der beiden TextViews liegt, weil wenn ich keine "setLayoutParams" an den beiden TextViews benutze, wird das TableLayout erstellt, ALLERDINGS sieht es nicht wie gewollt aus (die Spalten sind nicht gleich gross).
Aus irgendeinem Grund kann ich keine Layout-Parameter an den TextViews festlegen.
Was könnte ich machen..?
ich versuche ein TableLayout dynamisch (also per Code) zu erstellen.
Das Table Layout soll genau so aussehen..:
Code:
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp">
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="Field 1"
android:background="#0000FF"
android:textSize="13dp"
android:textColor="#fff"
android:includeFontPadding="false"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<TextView
android:text="Field 2"
android:background="#0000FF"
android:textSize="13dp"
android:textColor="#fff"
android:includeFontPadding="false"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
/>
</TableRow>
</TableLayout>
Code:
/* Table Layout */
final TableLayout table = new TableLayout(getApplicationContext());
TableLayout.LayoutParams lp_normal = new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
lp_normal.setMargins(getPixels(20), 0, getPixels(20), 0);
table.setLayoutParams(lp_normal);
table.setOrientation(TableLayout.HORIZONTAL);
/* ----------- */
/* Table Row */
TableRow row_1 = new TableRow(getApplicationContext());
row_1.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
/* -------- */
TableLayout.LayoutParams lp_txt = new TableLayout.LayoutParams(0, LayoutParams.FILL_PARENT);
lp_txt.weight = 1;
// TextView 1
final TextView txtField_1 = new TextView(getApplicationContext());
txtField_1.setTextColor(Color.WHITE);
txtField_1.setText("Field 1");
txtField_1.setLayoutParams(lp_txt);
txtField_1.setIncludeFontPadding(false);
row_1.addView(txtField_1);
// TextView 2
final TextView txtField_2 = new TextView(getApplicationContext());
txtField_2.setTextColor(Color.WHITE);
txtField_2.setIncludeFontPadding(false);
txtField_2.setText("Field 2");
txtField_2.setLayoutParams(lp_txt);
row_1.addView(txtField_2);
table.addView(row_1);
Ich glaube auch, dass es an das "setLayoutParams" der beiden TextViews liegt, weil wenn ich keine "setLayoutParams" an den beiden TextViews benutze, wird das TableLayout erstellt, ALLERDINGS sieht es nicht wie gewollt aus (die Spalten sind nicht gleich gross).
Aus irgendeinem Grund kann ich keine Layout-Parameter an den TextViews festlegen.
Was könnte ich machen..?
Zuletzt bearbeitet: