How to set the multiple lines in TextView Android Studio

This question does not have proper information about what you exactly want.

I can think of 2 possible cases.

CASE 1 : Writing in a new line in Text View.

Hi there

This is a single Text View

If this is what you want, but you get get something like

Hi there This is a single Text View

You can change lines using new line character ‘n’. Place this where the lines need to be changed.

Example:

XML :

  1. android:layout_width="wrap_content" 
  2. android:layout_height="wrap_content" 
  3. android:text="Hi there nThis is a single Text View" /> 

This will give you the desired format of the Text.

JAVA :

  1. TextView textView = findViewbyId(R.id.textView); 
  2. textView.setText("Hi there nThis is a single Text View"); 

Beware that the new line character should be appended with the word (“nHi”) and not with a space (“n Hi”).

CASE 2 : You want to set the maximum number of lines in Text View.

If you want to restrict the maximum number of lines in a text view , you can simply add the

  1. android:maxLines="some_positive_integer" 

to your Text View.

Example:

  1. android:layout_width="wrap_content" 
  2. android:layout_height="wrap_content" 
  3. android:maxLines="some_positive_integer" 
  4. android:text="Hi there nThis is a single Text View" /> 

Hope this helps.

If this was not required, feel free to ask it with proper example.