TableRow+TextView mit voller breite

  • Antworten:0
Stefan
  • Forum-Beiträge: 1

19.06.2012, 14:47:07 via Website

Hallo,

im Designer kann man TextViews hinzufügen und mit der Eigenschaft layout_weight=1 füllen diese die komplette Breite aus.

1<ScrollView android:layout_marginBottom="50dip" android:layout_height="wrap_content" android:layout_width="fill_parent">
2 <TableLayout
3 xmlns:android="http://schemas.android.com/apk/res/android"
4 android:id="@+id/plist"
5 android:layout_width="fill_parent"
6 android:layout_height="wrap_content"
7 android:stretchColumns="1"
8 android:padding="10dip">
9 <TableRow>
10 <TextView android:text="test" android:background="#0000ff"
11 android:layout_width="fill_parent"
12 android:layout_height="fill_parent"
13 android:layout_weight="1"></TextView>
14
15 </TableRow>
16 </TableLayout>
17 </ScrollView>

Da ich nicht weiß, wie viele TextViews angezeigt werden sollen, soll die Liste in Java gefüllt werden. Das bekomme ich aber nicht hin. Lasse ich bei tv LayoutParams weg, ist die TextView nur so breit wie der enthaltene Text. Setze ich LayoutParams, wird tv in row nicht angezeigt (die Zeile scheint leer zu sein).

Hat jemand eine Idee, wie man die Liste korrekt aufbaut?
Hier der Code

1private void FillTable(List<String> liste) {
2 TableLayout plist = (TableLayout) findViewById(R.id.plist);
3
4 for (String p : liste) {
5 TableRow row = new TableRow(thisInstance);
6
7 TableLayout.LayoutParams tableRowParams = new TableLayout.LayoutParams(
8 TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
9
10 int leftMargin = 0;
11 int topMargin = 0;
12 int rightMargin = 0;
13 int bottomMargin = 5;
14
15 tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
16
17 row.setLayoutParams(tableRowParams);
18
19 TextView tv = new TextView(thisInstance);
20 tv.setTextColor(Color.BLUE);
21 tv.setText(Html.fromHtml(p));
22
23 int resid = R.drawable.gradient_shape_green;
24 row.setBackgroundResource(resid);
25
26 tv.setTextSize(14);
27 tv.setPadding(10, 10, 10, 10);
28 tv.setTag(p);
29 tv.setOnClickListener(HandleTVClick);
30 tv.setBackgroundColor(Color.MAGENTA);
31 LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
32 LinearLayout.LayoutParams.FILL_PARENT, 1f);
33 row.addView(tv, lp);
34
35 plist.addView(row);
36 }
37 }

tia,
Stefan

Antworten