2012-04-24 83 views
2

我相信我之前看到過這樣的問題,但我無法在任何地方找到它......所以,我會發布我的問題版本,除非其他人知道鏈接它。阻止Android對話框縮進文本的每個段落

反正...

我有一個AlertDialog是造就了串在我strings.xml文件對話框內顯示。字符串看起來像這樣:

<string name="about_app"> 
     Blah blah blah talking about stuff this is a line 
     Oh look I continued onto another line! Now I want these...\n\n 

     So this is another paragraph! Intriguing. Yes, onto the next line 
     Android text doesn't necessarily consider this a new line, which is fine 
     becauase i only care about paragraphs, which I'm using backslash n's for!\n\n 

     And... here's my final statement! Woo.\n 

</string> 

所有東西在AlertDialog中都顯示正確(有些)。 「Blah blah blah ...」與AlertDialog的左邊緣對齊並繼續,直至遇到\n\n。從這裏,我得到我想要的間距「所以這是...」。然而,「這就是......」縮進了一個我無法擺脫的煩人的小空間!同樣的「而且......這是我的......」。有沒有人有解決這個問題?

說明:我試過在代碼中的每個段落之後擺脫空行 - 什麼都不做。我也確保在我的\n之後沒有空格。

+0

如何把\ n的段落的前面 - 是這樣的: '<字符串name =「about_app」> Blah等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等信息內容概述:現在我想要這些... \ n \ n所以這是另一款!耐人尋味。是的,到下一行 Android文本不一定認爲這是一個新行,這是好的 因爲我只關心段落,我使用反斜槓n的!\ n \ n並且...這是我的最後的聲明! Woo。\ n ' – Rajesh 2012-04-24 14:41:29

+0

以前的評論格式並沒有如我所料。我的意思是在段落的第一個字符之前使用'\ n'。 – Rajesh 2012-04-24 14:46:34

回答

4

您看到的額外空間是由字符串資源中段落的縮進引起的。當你打破這條界線時,你的縮進就成了詞語之間的分界線,你將​​它看作是空間。但是,如果有新行,縮進顯示爲每個段落開頭之前的空格。要擺脫它,你需要將你的\n直接放在下一段的第一個字母之前,或者不要縮進你的行。順便說一句,自行換行可能會導致渲染時產生空間。這兩種應該工作:

(1)

<string name="about_app"> 
     Blah blah blah talking about stuff this is a line 
     Oh look I continued onto another line! Now I want these...\n 

     \nSo this is another paragraph! Intriguing. Yes, onto the next line 
     Android text doesn't necessarily consider this a new line, which is fine 
     becauase i only care about paragraphs, which I'm using backslash n's for!\n 

     \nAnd...here's my final statement! Woo.\n 
</string> 

或(2)

<string name="about_app"> 
Blah blah blah talking about stuff this is a line 
Oh look I continued onto another line! Now I want these...\n\n 
So this is another paragraph! Intriguing. Yes, onto the next line 
Android text doesn't necessarily consider this a new line, which is fine 
becauase i only care about paragraphs, which I'm using backslash n's for!\n\n 
And...here's my final statement! Woo.\n 
</string> 
+0

我想我會用第一個解決方案去;謝謝!! – Mxyk 2012-04-24 17:03:46

+1

我使用以下解決方案來擺脫多餘的空間:String myString = getString(R.string.my_string).replace(「\ n」,「\ n」); – sagis 2015-05-27 09:53:53