2017-08-01 91 views
1

我的应用程序使用JSoup抓取网页,并从元素获取文本以放入字符串。当我用System.out正常打印字符串时,它会在多行上打印。Android TextView不显示多行,即使String有换行

但是,当我将字符串放入TextView使用setText(myStringname)时,文本显示但没有多行。我已将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! 

但它显示了IKE在此:

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(); 
+0

后的TextView XML代码 –

+0

更新我的问题与XML代码 –

+0

[MAXLINES使得TextView的至多多行高。(https://developer.android.com/reference/android/小部件/ TextView.html#attr_android:MAXLINES)。问题可能出在你的字符串上。显示所有相应的代码请致电 – PedroHawk

回答