2012-04-24 15 views
2

私はこれまでのような質問を見たことがあると思いますが、どこでも見つけられません...だから、他の誰かがそれのためのリンク。Androidのダイアログがテキストの各段落をインデントしないようにする

とにかく...

私は、ダイアログ内で表示するために私のstrings.xmlファイル内の文字列を育てているAlertDialogを持っています。文字列は次のようになります。

<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つの厄介な小さなスペースをインデントされています! 「...そして、私の...」と同じです。誰にもこれに対する解決策がありますか?

注:コード内の各段落の後に空白行を取り除こうとしましたが、何もしません。私はまた、\nの後にスペースがないことを保証しました。

+0

どの段落の前に\ nを置くことについて - このように: '<文字列名前= "about_app"> これは私が別の行に続けているものです。今私はこれらをしたい... \ n \ nこれは別の段落です!興味をそそる。はい、次の行に移動します Androidのテキストは必ずしもこの新しい行とはみなされません。 私はバックスラッシュのnを使用している段落についてのみ気にします!\ n \ nそして...最後の声明!うー。\ n ' – Rajesh

+0

私が期待したように、前のコメントの書式は出ていませんでした。私が意図したことは、段落の最初の文字の前に '\ n'を使うことでした。 – Rajesh

答えて

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

+1

私は余分なスペースを取り除くために以下の解決法を使用しました:String myString = getString(R.string.my_string).replace( "\ n"、 "\ n"); – sagis

関連する問題