Obwohl das viel wiederholte Frage aber erstes Mal für mich aussieht. Ich habe überall gesucht und konnte das Ergebnis nicht bekommen und landete hier.TableRow dynamisch zu TableLayout in XML hinzufügen
Ich erstelle eine Tabelle dynamisch, von der der TableLayout
Teil in Xml-Teil geschrieben wird.
<RelativeLayout
android:layout_width="70dp"
android:layout_height="40dp"
android:background="@color/colorPrimaryDark"
android:id="@+id/componentA">
<TableLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center"
android:id="@+id/tl_componentA">
</TableLayout>
</RelativeLayout>
Ich habe ein Objekt für die Tabelle
TableLayout tableLayoutA;
tableLayoutA= (TableLayout)view.findViewById(R.id.tl_componentA);
Jetzt habe ich versucht, von hier an als
createTableRowColumn(tableLayoutA);
zugehörigen Funktionen sind
private void createTableRowColumn(TableLayout tableLayout){
TableRow tableRow1= new TableRow(this.context);
tableRow1.setBackgroundColor(getResources().getColor(R.color.colorAccent));
setTableRowColumnProperty(tableRow1);
tableLayout.addView(tableRow1);
}
eine Zeile dynamisch hinzufügen private void setTa bleRowColumnProperty (TableRow TableRow) {
TableRow.LayoutParams layoutParams= new TableRow.LayoutParams(70, 40);
tableRow.setLayoutParams(layoutParams);
}
Ich tat dies alles und nichts hat mir gezeigt, in der emulater. Aber als ich dieselbe Struktur in XML manuell gab, dann funktionierte die Sache gut.
Aus diesem Grund habe ich versucht, etwas
Toast.makeText(getContext(), tableLayoutA.getHeight()+"", Toast.LENGTH_LONG).show();
In Toast, um herauszufinden, es war mir zeigt 0. ich nicht, warum bekommen konnte, obwohl ich die Größe für tableLayoutA in der selbst xml behoben haben.
Können Sie es bitte ausarbeiten? –
Wie auch immer, ich verstehe durch dynamische, wenn sich Daten in Ihrem TableLayout ständig ändern, ist das, was Sie sagen wollen? oder –
Kannst du bitte den Code korrigieren und posten, damit ich dorthin komme, wo ich falsch liege? –