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ます。ここから、「これは...」の前に必要な間隔を取得します。しかし、「だからこれは...」は、私が取り除くことができない1つの厄介な小さなスペースをインデントしています! 「And... here's my...」も同様です。誰にもこれに対する解決策がありますか?

注:コードの各段落の後に空の行を削除しようとしましたが、何もしません。また、s の後にスペースがないことも確認しました\n

4

1 に答える 1

6

表示される余分なスペースは、文字列リソース内の段落のインデントが原因です。行を改行すると、インデントが単語間の区切りとして機能し、それがスペースとして表示されます。ただし、改行がある場合、インデントは各段落の先頭の前にスペースとして表示されます。それを取り除くに\nは、次の段落の最初の文字の直前に直接置くか、行をインデントしない必要があります。ところで、改行だけでもレンダリング時にスペースが生じる場合があります。次の 2 つのいずれかが機能するはずです。

(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 に答える