TextView is used to display text on Android application. By default, TextView displays text on one line and if long, TextView will automatically display with more lines to display its text in the most logical way.
Android developers can create a new line on TextView both in programming and syntax. Android developers can create multiline TextView without dividing text into multiple lines according to android: minLines properties.
The following android example code shows us the TextView utility with the xml layout file and the string resource file.
Create layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
androidrientation="vertical">
<TextView
android:id="@+id/text_view1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:background="#DA70D6"
android:text="This is line 1 \nThis is line 2 \nLine number 3"
/>
<TextView
android:id="@+id/text_view2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:background="#DEB887"
android:text="This is line 1 \nThis is line 2 \nLine number 3"
android:maxLines="2"
/>
<TextView
android:id="@+id/text_view3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:background="#8FBC8F"
android:text="This is line 1 \nThis is line 2"
android:minLines="3"
/>
<TextView
android:id="@+id/text_view4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:background="#5F9EA0"
android:text="@String/Multiline_Text_By_N"
/>
</LinearLayout>
Android developers can create a new line on TextView both in programming and syntax. Android developers can create multiline TextView without dividing text into multiple lines according to android: minLines properties.
The following android example code shows us the TextView utility with the xml layout file and the string resource file.
Create layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
androidrientation="vertical">
<TextView
android:id="@+id/text_view1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:background="#DA70D6"
android:text="This is line 1 \nThis is line 2 \nLine number 3"
/>
<TextView
android:id="@+id/text_view2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:background="#DEB887"
android:text="This is line 1 \nThis is line 2 \nLine number 3"
android:maxLines="2"
/>
<TextView
android:id="@+id/text_view3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:background="#8FBC8F"
android:text="This is line 1 \nThis is line 2"
android:minLines="3"
/>
<TextView
android:id="@+id/text_view4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:background="#5F9EA0"
android:text="@String/Multiline_Text_By_N"
/>
</LinearLayout>