Android TextView没有显示多行,即使String有换行符

时间:2017-08-01 17:38:30

标签: android string textview newline

我的应用程序使用JSoup抓取一个网页,并从元素中获取文本以放入String。当我用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();

1 个答案:

答案 0 :(得分:0)

我不知道Jsoup。但你似乎在清理换行符。请点击此链接:Preserve <br> tags when cleaning with Jsoup

相关问题