How to start first line in text view(paragraph) in middle - android

Viewed 228

I am new to Android. I have a paragraph in string which looks like below

String my_paragraph ="Software is a set of instructions, data or programs used to operate computers and execute specific tasks. It is the opposite of hardware, which describes the physical aspects of a computer. Software is a generic term used to refer to applications, scripts and programs that run on a device."
textView.setText(my_paragraph);

I want to display it in the Text View like this below image:

enter image description here

But what I got is I added below

enter image description here

I want the first line in text view(paragraph) should starts in the middle. I don't want to add leading spaces in string. I don't know how to achieve this. Please help me with some solutions.

2 Answers

Android has libraries that can do this for you. I found an old post with a great how to use the SpannableString and LeadingMarginSpan libraries.

The question can be found at: What is Leading Margin in Android?

try to add \t or \u0009 (tabulator character) at the begining of String - this is a symbol of default indetation for paragraphs

textView.setText("\u0009" + my_paragraph);
Related