TextView inadvertently indents first line

Viewed 50

I use TextView objects to contain a long descriptive text on a page in my app. Each object holds one paragraph, populated by an XML resource string:

<string>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse 
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat 
    non proident, sunt in culpa qui officia deserunt mollit anim id est 
    laborumenter
</string>

However, the first line of each paragraph apparently is automatically indented one letter position. This is not what I want. I want the first line to start at the same vertical line as the other lines of the paragraph.

Does the TextView class feature a method that controls indentation? How can I at all override this indentation?

PS: this problem has probably nothing to do with margins or padding. They work as intended for setting the layout of the text.

1 Answers

It turns out that the way you type in the text in xml determines whether there will be an indent or not. This is how I originally put the source text for one of those TextView objects in xml:

<string>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse 
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat 
    non proident, sunt in culpa qui officia deserunt mollit anim id est 
    laborumenter
</string>

So that gave an indentation at the start of the first line. I have now changed it to ...

<string>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse 
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat 
    non proident, sunt in culpa qui officia deserunt mollit anim id est 
    laborumenter
</string>

... and the indentation is gone. I always thought that formatting (adding spaces, starting on a new line etc.) between string tags in xml didn't affect layout. Apparently, it does.

Related