T
Tom299
Stammgast
- 122
Hi,
ich kämpfe schon die ganze Zeit mit dem Problem, daß die TableRow, die ich dynamisch im Code erzeuge, nicht mit den Spalten der TableRows aus dem XML übereinstimmt ...
Mein XML dazu (die 2. TableRow hab ich zu Testzwecken hinzugefügt, um zu sehen, ob sie richtig oder auch verschoben ist, ist aber richtig):
mein Code-Ausschnitt:
Ich hab auch beim ersten LayoutParams mal TableLayout anstatt TableRow genommen, macht aber keinen Unterschied. Ich weiß langsam nicht mehr weiter ...
Wenn ich layout_weight der 1. Spalte im Code auf 0.55f setze, dann sind die ersten 2 Spalten richtig untereinander, die nachfolgenden verschieben sich dann aber wieder ...
Sieht jemand den Fehler?
ich kämpfe schon die ganze Zeit mit dem Problem, daß die TableRow, die ich dynamisch im Code erzeuge, nicht mit den Spalten der TableRows aus dem XML übereinstimmt ...
Mein XML dazu (die 2. TableRow hab ich zu Testzwecken hinzugefügt, um zu sehen, ob sie richtig oder auch verschoben ist, ist aber richtig):
Code:
<TableLayout
android:id="@+id/overview_table_layout_status_medium_art"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<TableRow
android:id="@+id/overview_table_row_status_medium_art_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/overview_status_medium_art_text_tvArt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Small"
android:gravity="left"
android:layout_weight="0.4"
android:text="Test1"
/>
<TextView
android:id="@+id/overview_status_medium_art_text_tvStrom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Small"
android:gravity="center"
android:text="@string/overview_status_text_medium_strom"
android:layout_weight="0.15"
/>
<TextView
android:id="@+id/overview_status_medium_art_text_tvWasser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Small"
android:gravity="center"
android:text="@string/overview_status_text_medium_wasser"
android:layout_weight="0.15"
/>
<TextView
android:id="@+id/overview_status_medium_art_text_tvGas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Small"
android:gravity="center"
android:text="@string/overview_status_text_medium_gas"
android:layout_weight="0.15"
/>
<TextView
android:id="@+id/overview_status_medium_art_text_tvFernwaerme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Small"
android:gravity="center"
android:text="@string/overview_status_text_medium_fernwaerme"
android:layout_weight="0.15"
/>
</TableRow>
<TableRow
android:id="@+id/overview_table_row_test"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/overview_status_medium_art_text_tvArt_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Small"
android:gravity="left"
android:layout_weight="0.4"
android:text="Test2"
/>
<TextView
android:id="@+id/overview_status_medium_art_text_tvStrom_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Small"
android:gravity="center"
android:text="50"
android:layout_weight="0.15"
/>
<TextView
android:id="@+id/overview_status_medium_art_text_tvWasser_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Small"
android:gravity="center"
android:text="25"
android:layout_weight="0.15"
/>
<TextView
android:id="@+id/overview_status_medium_art_text_tvGas_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Small"
android:gravity="center"
android:text="15"
android:layout_weight="0.15"
/>
<TextView
android:id="@+id/overview_status_medium_art_text_tvFernwaerme_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Small"
android:gravity="center"
android:text="10"
android:layout_weight="0.15"
/>
</TableRow>
</TableLayout>
mein Code-Ausschnitt:
Code:
TableLayout layoutTableMediumArt = (TableLayout)findViewById(R.id.overview_table_layout_status_medium_art);
TableRow tabRow = new TableRow(this);
TableRow.LayoutParams paramsTabRow = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
tabRow.setLayoutParams(paramsTabRow);
TableRow.LayoutParams paramsTextViewArt = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
paramsTextViewArt.gravity = Gravity.LEFT;
paramsTextViewArt.weight = 0.4f;
TextView tvArt = new TextView(this);
tvArt.setLayoutParams(paramsTextViewArt);
tvArt.setText("Test3");
tvArt.setSingleLine(true);
tvArt.setTextAppearance(this, android.R.style.TextAppearance_Small);
tabRow.addView(tvArt);
TableRow.LayoutParams paramsTextViewWert = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
paramsTextViewWert.gravity = Gravity.CENTER;
paramsTextViewWert.weight = 0.15f;
TextView tvWertArtStrom = new TextView(this);
tvWertArtStrom.setLayoutParams(paramsTextViewWert);
tvWertArtStrom.setText("50");
tvWertArtStrom.setSingleLine(true);
tvWertArtStrom.setTextAppearance(this, android.R.style.TextAppearance_Small);
tabRow.addView(tvWertArtStrom);
TextView tvWertArtWasser = new TextView(this);
tvWertArtWasser.setLayoutParams(paramsTextViewWert);
tvWertArtWasser.setText("25");
tvWertArtWasser.setSingleLine(true);
tvWertArtWasser.setTextAppearance(this, android.R.style.TextAppearance_Small);
tabRow.addView(tvWertArtWasser);
TextView tvWertArtGas = new TextView(this);
tvWertArtGas.setLayoutParams(paramsTextViewWert);
tvWertArtGas.setText("15");
tvWertArtGas.setSingleLine(true);
tvWertArtGas.setTextAppearance(this, android.R.style.TextAppearance_Small);
tabRow.addView(tvWertArtGas);
TextView tvWertArtFernwaerme = new TextView(this);
tvWertArtFernwaerme.setLayoutParams(paramsTextViewWert);
tvWertArtFernwaerme.setText("10");
tvWertArtFernwaerme.setSingleLine(true);
tvWertArtFernwaerme.setTextAppearance(this, android.R.style.TextAppearance_Small);
tabRow.addView(tvWertArtFernwaerme);
layoutTableMediumArt.addView(tabRow);
Ich hab auch beim ersten LayoutParams mal TableLayout anstatt TableRow genommen, macht aber keinen Unterschied. Ich weiß langsam nicht mehr weiter ...
Wenn ich layout_weight der 1. Spalte im Code auf 0.55f setze, dann sind die ersten 2 Spalten richtig untereinander, die nachfolgenden verschieben sich dann aber wieder ...
Sieht jemand den Fehler?