How to indent text string in TextView in Android?

I write text in android that takes more than two lines, now my problem is how I backtrack my text lines from the second line.

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 does not start immediately, but to the right of the name

+4
source share
3 answers

Use LeadingMarginSpan.Standardwith SpannableString, or if you also need bullets, use 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, every time you need an indented line that you can do:

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

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

+14

\t \n . \t . :

    textView.setSingleLine(false);
    textView.setText("1.my name is qadeer hussain\n\tiam fine how  Ru.");
+4

Try using \tup what you want indented. Use more if you need to retreat further.

+2
source

Source: https://habr.com/ru/post/1537363/


All Articles