Problem mit Mehrzeiligem TextView.

  • Antworten:4
  • Bentwortet
Sascha N.
  • Forum-Beiträge: 60

23.12.2011, 06:16:29 via Website

Hallo, Wiedermal ich :)

Ich lade die Daten ja aus einer XML datei. Nun möchte ich wenn die Displaybreite erreicht ist und der Text Länger ist als der Bildschirm das die Zeile automatisch umgebrochen wird. Aber irgend wie geht das nicht. Hier mal meine TextView eigenschaft aus der XML datei. Evtl. kann ja jemand meinen Fehler sehen. Habe schon Google befragt dazu aber sämtliche hilfen diesbezüglich haben mir auch keinen erfolg gebracht.

1<TextView
2 android:id="@+id/subject"
3 android:layout_width="fill_parent"
4 android:layout_height="wrap_content"
5 android:text="TreffenSubject"
6 android:textSize="12sp"
7 android:textStyle="bold" android:textColor="#003366" android:scrollHorizontally="false" android:inputType="text|textMultiLine|textLongMessage" android:maxLines="2" android:minLines="1" android:lines="2" android:layout_gravity="fill" android:gravity="fill">
8 </TextView>

hoffe es weiss Jemand Rat.

Antworten
Markus Gu
  • Forum-Beiträge: 2.644

23.12.2011, 09:24:02 via Website

und was ist das ergebnis? Nur eine zeile ? Mehrzeilig ?

ich würde es so machen:

<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="asdfaflkjadsö fjadsöl fjasdöl fkjadlsöfk jalödsk fjaldksf hjladksfh alkdsjfh alkjdfh lkadjh aklsjdfh lkajsdhflka jdhsflk ashdfkl"
android:maxLines="2" />

das müsste eigenltich reichen

swordiApps Blog - Website

Antworten
Sascha N.
  • Forum-Beiträge: 60

25.12.2011, 04:37:11 via Website

Hallo Markus. Ich habe es mit deiner definition versucht. Aber die Zeile geht ins Leere vom Display. Also überlänge endet im nichts.... wie abgeschnitten.

Kann es sein das es daran liegt das ich das in einem Table Layer habe ?

hier mal die Komplette itemview.xml

1<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 android:id="@+id/tableLayoutMain"
3 android:layout_width="fill_parent"
4 android:background="#FFFFFF"
5 android:layout_height="wrap_content" >
6
7 <TableRow
8 android:id="@+id/tableRowMain1"
9 android:layout_width="fill_parent"
10 android:layout_height="wrap_content" android:gravity="fill" android:orientation="horizontal">
11
12 <ImageView
13 android:id="@+id/TypeView"
14 android:layout_width="wrap_content"
15 android:layout_height="wrap_content"
16 android:paddingTop="8px" android:paddingRight="2px" android:paddingLeft="2px" android:paddingBottom="2px"/>
17
18 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
19 android:id="@+id/tableLayoutClient"
20 android:layout_width="fill_parent"
21 android:background="#FFFFFF"
22 android:layout_height="wrap_content">
23 <TableRow
24 android:id="@+id/tableRowClient1"
25 android:layout_width="fill_parent"
26 android:layout_height="wrap_content">
27<TextView
28 android:id="@+id/subject"
29 android:layout_width="fill_parent"
30 android:layout_height="wrap_content"
31 android:text="TreffenSubject"
32 android:textSize="12sp"
33 android:textStyle="bold"
34 android:textColor="#003366"
35 android:maxLines="2" />
36
37 </TableRow>
38
39 <TableRow
40 android:id="@+id/tableRowClient2"
41 android:layout_width="wrap_content"
42 android:layout_height="wrap_content" >
43
44 <LinearLayout
45 android:id="@+id/linearLayout1"
46 android:layout_width="wrap_content"
47 android:layout_height="wrap_content" >
48
49 <TextView
50 android:id="@+id/OrtCaption"
51 android:layout_width="wrap_content"
52 android:layout_height="wrap_content"
53 android:text="Ort :" android:textColor="#000000" android:textSize="11sp" android:visibility="visible" android:textStyle="bold"/>
54
55 <TextView
56 android:id="@+id/OrtView"
57 android:layout_width="wrap_content"
58 android:layout_height="wrap_content"
59 android:text="Ort" android:textSize="11sp" android:textColor="#555555" android:paddingRight="15px"/>
60
61 <TextView
62 android:id="@+id/PlatzCaption"
63 android:layout_width="wrap_content"
64 android:layout_height="wrap_content"
65 android:text="Platz :" android:textSize="11sp" android:textColor="#000000" android:textStyle="bold"/>
66
67 <TextView
68 android:id="@+id/PlatzView"
69 android:layout_width="wrap_content"
70 android:layout_height="wrap_content"
71 android:text="Platz" android:textSize="11sp" android:textColor="#555555"/>
72
73 </LinearLayout>
74
75 </TableRow>
76 <TableRow
77 android:id="@+id/tableRowClient3"
78 android:layout_width="wrap_content"
79 android:layout_height="wrap_content" >
80 <LinearLayout
81 android:id="@+id/linearLayout1"
82 android:layout_width="wrap_content"
83 android:layout_height="wrap_content" >
84 <TextView
85 android:id="@+id/DateCaption"
86 android:layout_width="wrap_content"
87 android:layout_height="wrap_content"
88 android:text="Zeitraum :"
89 android:textColor="#000000"
90 android:textSize="10sp" android:textStyle="bold"/>
91
92 <TextView
93 android:id="@+id/DateView"
94 android:layout_width="wrap_content"
95 android:layout_height="wrap_content"
96 android:text="vom 11.02.2011 bis 12.02.2011"
97 android:textColor="#555555"
98 android:textSize="10sp" />
99 </LinearLayout>
100 </TableRow>
101 </TableLayout>
102 </TableRow>
103
104 </TableLayout>

Oder kann man das evtl anders bewerkstelligen ?? und vor allem einfacher ?

gruss Sascha....

Antworten
Markus Gu
  • Forum-Beiträge: 2.644

25.12.2011, 13:58:06 via Website

ich bin mir nicht sicher, was du genau willst?

du sagtest doch du möchtest eine textview, die maximal 2 zeilen hat. das macht mein code. wenn der text länger ist, muss der text ja dann irgendwo verschwinden.

du kannst evtl noch mit android:ellipsize="" spielen.

zu deinem layout:
du hast schon verdammt viel tablelayouts und rows da drin. kennst du das relativLayout? das machts ein wenig einfacher, glaub ich.

swordiApps Blog - Website

Antworten
Sascha N.
  • Forum-Beiträge: 60

25.12.2011, 14:41:05 via Website

Mit relative Layout habe ich mich noch nicht beschäftigt. aber ich habe nun die TabellenViews raus genommen und durch LinearLayouts ersetzt und nun wird die Zeile automatisch umgebrochen wenn sie länger ist als der bildschirm. Lag wohl wirklich an den Tabellen....

Mit relative Layout ?? muss ich mal schauen wie die Funktionieren... :)

Antworten