私の Android レイアウトには、画面の使用可能な幅の半分を使用する TextView があります。実行時に、テキストを (長い) 電子メール アドレスに設定します。例えば:
googleandroiddeveloper@gmail.com
テキストが 1 行に収まらない場合、Android は改行を挿入しますが、これは望ましい動作です。ただし、改行位置は、行に収まらない最初の文字の前です。結果は次のようになります。
googleandroiddeveloper@gmai
l.com
これは、特に電子メールアドレスでは、ちょっと見苦しいと思います。文字の直前に改行を表示したい@
:
googleandroiddeveloper
@gmail.com
もちろん、 に を追加することもでき\n
ますstrings.xml
。しかし、電子メール アドレスは、1 行に収まる場合でも、常に 2 行を使用します。
\u200B
メールアドレスにZERO WIDTH SPACE ( ) を追加することで解決策を見つけたとすでに思っていました。
<string name="email">googleandroiddeveloper\u200B@gmail.com</string>
ただし、標準のスペース以外では、Android は特殊なスペース文字を改行可能なスペースとして検出しないため、この時点で改行を追加しません。
アプリケーションの複数の場所で多くの電子メール アドレスを扱っているため、文字の前に壊れやすく目に見えないスペースを追加するソリューションを探しています@
。そのため、Android は、1 行に収まらない場合に電子メール アドレスをラップします。