【发布时间】:2018-01-08 17:05:28
【问题描述】:
我的应用程序使用 JSoup 抓取网页,并从元素中获取文本以放入字符串。当我使用System.out 正常打印字符串时,它会打印在多行上。
但是,当我使用 setText(myStringname) 将字符串放入 TextView 时,文本会显示,但不会超过一行。我已将 android:maxLines 设置为 16。我使用 articleDescs=articleDescs.replaceAll("(\\r|\\n|\\r\\n)+",System.getProperty("line.separator")); 将其他内容替换为系统换行符。
假设我的 TextView 字符串是Welcome to the TextView! \nWhat are we doing? \nPrinting new lines!我希望文本显示为
Welcome to the TextView!
What are we doing?
Printing new lines!
但它显示如下:
Welcome to the TextView! What are we doing? Printing new lines!
如何让它多行显示文本?我尝试查看其他问题,但他们告诉我去做maxLines,我照做了。谢谢
编辑:TextView XML
<TextView
android:id="@+id/itemDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tv_placeholder"
android:maxLines="16"
android:layout_marginLeft="10dp"/>
String pretty=Jsoup.clean(aPrep,"",Whitelist.none().addTags("br","p"),new Document.OutputSettings().prettyPrint(true));
String articleDescs=Jsoup.clean(pretty,"",Whitelist.none(),new Document.OutputSettings().prettyPrint(false));
articleDescs=articleDescs.replaceAll("(\\r|\\n|\\r\\n)+","\n");
System.out.println(articleDescs);
String articleImgURLs=articleImgURLsArray;
articleDescs=Jsoup.parse(articleDescs).text();
【问题讨论】:
-
发布 textview xml 代码
-
用 xml 代码更新了我的问题
-
maxLines makes the TextView be at most that many lines tall.。问题可能出在您的字符串上。请显示所有相应的代码
-
@PedroHawk 我更新了我的问题
-
您是否尝试过设置静态文本,比如说
Row1\nRow2没有replaceAll替换?
标签: android string textview newline