3

我相信我以前见过这样的问题,但我在任何地方都找不到它......所以,除非其他人知道它的链接,否则我会发布我的问题版本。

无论如何...

我有一个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。从这里,我在“所以这是……”之前得到了我想要的间距。然而,“所以这是……”缩进了一个我无法摆脱的烦人的小空格!“而且……这是我的……”也是如此。有人对此有解决方案吗?

注意:我已经尝试在代码中的每个段落之后去掉空行 - 什么都不做。我还确保在我的 s 之后没有空格\n

4

1 回答 1

6

您看到的额外空间是由字符串资源中段落的缩进引起的。当您只是换行时,您的缩进充当单词之间的分隔符,您将其视为空格。但是,当您有一个换行符时,缩进显示为每个段落开头之前的空格。要摆脱它,您需要将您的\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>
于 2012-04-24T15:13:07.077 回答