Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I indent a text line in TextView in android?

Tags:

android

I am writing a text in android which take more than two lines now my problem is how I indent the second line my text lines are.

1.my name is qadeer hussain

iam fine how  Ru.

but I want

1.my name is qadeer hussain

     iam fine how  Ru.

here the second line not start right below the one but it right below the name

like image 819
Qadeer Hussain Avatar asked Apr 21 '14 11:04

Qadeer Hussain


2 Answers

Use a LeadingMarginSpan.Standard with a SpannableString, or if you also need bullets use a BulletSpan:

Just create a function like this:

static SpannableString createIndentedText(String text, int marginFirstLine, int marginNextLines) {
    SpannableString result=new SpannableString(text);
    result.setSpan(new LeadingMarginSpan.Standard(marginFirstLine, marginNextLines),0,text.length(),0);
    return result;
}

And then, everytime you need an indented line you can do:

myTextView.setText(createIndentedText("my text that's gonna be indented", 10, 10));

The first parameter is the indentation of the first line, the second parameter is the indentation of the next lines, just in case you want to indent the first line differently to the following ones.

like image 100
rupps Avatar answered Oct 20 '22 03:10

rupps


Try using a \t before what you want to indent. Use more if you need to indent it further

like image 25
tf.alves Avatar answered Oct 20 '22 04:10

tf.alves