automatischer zeilenumbruch in textview

  • Antworten:6
Alkahna
  • Forum-Beiträge: 7

17.06.2011, 09:05:34 via Website

hi

ich habe folgendens Problem:
in einer Textview
1<ScrollView
2 android:id="@+id/ScrollView01"
3 android:layout_width="fill_parent"
4 android:layout_marginTop="15sp"
5 android:layout_height="wrap_content">
6 <TextView android:text="TextView"
7 android:id="@+id/erg"
8 android:layout_marginTop="15sp"
9 android:isScrollContainer="true"
10 android:scrollHorizontally="true"
11 android:layout_height="wrap_content"
12 android:layout_width="match_parent"
13 style="@style/txt">
14 </TextView>
15</ScrollView>
wird ein String angeliefert, der angezeigt werden soll.

Der String sieht in der Rohform so aus:
[code]
sn_erg = sn_erg + "\n\n" + "text" + ":" +
"\n" + "text" + " " + sn_netadr[0][0] + "." + sn_netadr[0][1] + "." + sn_netadr[0][2] + "." + sn_netadr[i][3] +
"\n" + "text" + " " + sn_firsthost[0][0] + "." + sn_firsthost[0][1] + "." + sn_firsthost[0][2] + "." + sn_firsthost[i][3] +
"\n" + "text" + " " + sn_lasthost[0][0] + "." + sn_lasthost[0][1] + "." + sn_lasthost[0][2] + "." + sn_lasthost[i][3] +
"\n" + "text" + " " + sn_br[0][0] + "." + sn_br[0][1] + "." + sn_br[0][2] + "." + sn_br[i][3] + "\n";
[/code]
(wieso der code nicht als code dargestellt wird ka^^)

Leider passiert es, dass mir eine Textzeile aus dem Display nach rechts "ausbricht", sprich man kann nur die hälfte des textes lesen.

Kann man die Textview so konfigurieren, dass Text, der über die Breite der Textview hinausgeht automatisch in die nächste Zeile rutscht??
Wär cool wenn mir da jmd helfen könnte.

mfg Alkahna

Antworten
Stefan S.
  • Forum-Beiträge: 560

17.06.2011, 11:25:38 via Website

Es gibt ein Property Multyline auf der Textview. Dann bricht sie automatisch.

Antworten
Alkahna
  • Forum-Beiträge: 7

17.06.2011, 11:40:03 via Website

danke für den Tipp aber die Eigenschaft hab ich nicht gefunden....

nur das gegenteil:
1android:singleLine="false"
(funktioniert aber auch nicht)

ab welcher api version soll es das Multiline property denn geben?

Ich entwickle für 2.2.1 also API 8

EDIT:

bin fündig geworden:

hab einfach die Zeile:
1android:scrollHorizontally="true"
auf
1android:scrollHorizontally="false"
geändert und schon hats den Text automatisch umgebrochen.

trozdem danke an alle

mfg Alkaha

— geändert am 17.06.2011, 12:07:58

Antworten
Stefan S.
  • Forum-Beiträge: 560

17.06.2011, 13:25:14 via Website

Ich meinte auch Singleline :) sorry.

Es gibt noch das Property InputType. Ich glaube dort kannst du Multilne oder so eingeben.

Antworten
Alkahna
  • Forum-Beiträge: 7

17.06.2011, 14:51:39 via Website

Es gibt noch das Property InputType. Ich glaube dort kannst du Multilne oder so eingeben.

nicht ganz, da kann man festlegen ob es sich bei der Eingabe um Text, ein password, eine Nummer, Telephonnummer oder so handelt.

bei mir hat geholfen:

android:scrollHorizontally="false" <- hatte ich vorher auf true
und android:singleLine="false".

mfg Alkahna

Antworten
Stefan S.
  • Forum-Beiträge: 560

17.06.2011, 16:11:20 via Website

Nein, das was Du meinst heisst Input method (Number, Password etc...)
Es gibt aber noch den Input Type :)

Antworten
Christoph Wittstock
  • Forum-Beiträge: 7

13.10.2011, 18:03:48 via Website

Ich muss dieses Thema nochmal aufgreifen, da mich alle 3 Eigenschaften nicht weiter brachten. Meine View sieht folgendermaßen aus:
1<?xml version="1.0" encoding="utf-8"?>
2<ScrollView android:id="@+id/scrollView1" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent">
3<LinearLayout
4 android:layout_width="match_parent"
5 android:orientation="vertical" android:layout_height="wrap_content">
6 ...
7 <LinearLayout
8 android:layout_width="match_parent"
9 android:orientation="vertical" android:layout_height="wrap_content">
10 <TextView android:id="@+id/commentsTitle" android:layout_height="wrap_content" android:text="@string/comments" android:layout_width="match_parent" android:gravity="center_horizontal" android:shadowColor="#f00" android:shadowRadius="3" android:textSize="22dip" android:layout_marginTop="5dip" android:layout_marginBottom="5dip"></TextView>
11 <TableLayout android:id="@+id/list_comments" android:layout_height="wrap_content" android:layout_width="match_parent"></TableLayout>
12 </LinearLayout>
13</LinearLayout>
14</ScrollView>

In das Tablelayout mit der ID list_comments werden dynamisch folgende TableRows eingefügt:
1<?xml version="1.0" encoding="utf-8"?>
2<TableRow xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/commentRow" android:layout_height="wrap_content" android:layout_width="match_parent" android:longClickable="true" android:clickable="false">
3 <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="wrap_content">
4 <LinearLayout android:id="@+id/linearLayout2" android:layout_width="match_parent" android:orientation="horizontal" android:layout_height="wrap_content">
5 <TextView android:text="TextView" android:id="@+id/comment_list_name" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="5dip" android:layout_marginRight="5dip" android:layout_marginTop="5dip" android:textStyle="bold"></TextView>
6 <TextView android:text="TextView" android:id="@+id/comment_list_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dip" android:textStyle="italic" android:textSize="10dip"></TextView>
7 </LinearLayout>
8 <TextView android:id="@+id/comment_list_text" android:layout_height="wrap_content" android:layout_marginLeft="5dip" android:layout_marginRight="5dip" android:singleLine="false" android:scrollHorizontally="false" android:layout_width="match_parent" android:inputType="textMultiLine"></TextView>
9
10 <TextView android:id="@+id/comments_seperator" android:layout_height="1dip" android:background="#333" android:layout_width="match_parent" android:layout_marginTop="5dip"></TextView>
11 </LinearLayout>
12</TableRow>

Wie man sieht, hat die TextView mit der ID comment_list_text die drei in diesem Thread angesprochenen Eigenschaften. Dennoch laufen meine Zeilen innerhalb dieser TextView rechts aus dem Bild heraus. Ich füge mal ein Bild an, dass diesen Zustand zeigt.



Ich hoffe es weiß jemand Rat. Vielen Dank.

Antworten