2012-08-17 85 views
3

我使用TextView來顯示文本,它由幾個段落組成。事情是這樣的:TextView中段落之間的距離

<TextView 
    android:text="@string/foo" 
/> 

<resources> 
    <string name="foo">Great Gauss! - cried Klapaucius - And where are the gruncheons? Where my dear, favorite pritons? Where now the gentle zits?!\nThey no longer are, nor ever will exist again - the machine said calmly - I executed, or rather only began to execute, your order...</string> 
<resources> 

我怎樣才能改變不影響(一個段落的多條線路之間的距離)行間段落之間的距離?

編輯: 也許我不夠精確。是的,我知道,因爲我用「\ n」換行,我可以 - 比喻 - 用「\ n \ n」做兩個換行符。或者使用HTML做這兩個換行符。但是,我正在尋找一種方法來確定,例如,段落之間的空間恰好是17傾角。就像我可以(爲例)做CSS:

p { 
    margin-bottom: 21px; 
} 
+0

使用這種\ n在字符串 – 2012-08-17 11:22:39

+0

我認爲搖滾是對的,但是,伸出澄清之間的下一行,該建議是添加額外\ n在段落之間放置一個空行。如果你想更多的控制使用HTML如下。 – 2012-08-17 11:28:52

+0

您可以使用Spannables來實現此目的:http://stackoverflow.com/a/42691246/1073151 – 2017-03-10 05:35:35

回答

0

可以使用的,而不是像這樣

Textview.setText(Html.fromHtml(" This portion Contains text with <b>html<b> <br/> <p> tags and others as per your requirement.</p> ")); 

希望這有助於你正常的文本HTML文本...

2

你可以考慮爲您的字符串使用HTML。這也將有利於讓您使用粗體,斜體的額外好處等

在strings.xml,你需要使用下面的代碼<>

&lt; &gt; 

含義「少比'和'大於'。以下代碼將< br/>作爲額外的行。

<resources> 
    <string name="foo">Great Gauss! - cried Klapaucius - And where are the gruncheons? Where my dear, favorite pritons? Where now the gentle zits?! &lt;br/&gt;They no longer are, nor ever will exist again - the machine said calmly - I executed, or rather only began to execute, your order...</string> 
<resources> 

設置你的TextView仍然比較相似,

message = getString(R.string.foo); 
textView.setText(Html.fromHtml(message));