Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line break in Android adds padding

I have 5-10 lines of address information that I want to insert in a layout in my Android app. I rather not use seperate textviews, but want to have one where I can insert line breaks manually.

I do this by adding \n and it seems to work, BUT.. This also adds padding or a space, I'm not sure which one.

Example:

This XML

<string name="contact_address">
    Street address\n
    City\n
    Country
</string>

Gives this output:

Street address
 City
 Country

Anyone know what could be wrong, or do I have to give up and make 5-10 seperate textviews?

like image 442
Andreas Avatar asked Jan 21 '11 11:01

Andreas


2 Answers

Try:

<string name="contact_address">Street address\nCity\nCountry</string>

to get rid of the spaces you are putting into your XML.

like image 84
CommonsWare Avatar answered Sep 27 '22 22:09

CommonsWare


I stumbled upon this and figured out a better way to keep the XML formatting and the line breaks without additional padding.

Use

<string>Line 1
      \nLine 2
      \nLine 3
</string>

Instead of

<string>Line 1\n
        Line 2\n
        Line 3
</string>
like image 25
Suriya Avatar answered Sep 27 '22 22:09

Suriya