Multiline TextView in Android?
If the text you're putting in the TextView
is short, it will not automatically expand to four lines. If you want the TextView
to always have four lines regardless of the length of the text in it, set the android:lines
attribute:
<TextView
android:id="@+id/address1"
android:gravity="left"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:maxLines="4"
android:lines="4"
android:text="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."></TextView>
You can do this with TableRow, see below code
<TableRow >
<TextView
android:id="@+id/tv_description_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="8dp"
android:text="@string/rating_review"
android:textColor="@color/black"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:maxLines="4"`enter code here`
android:padding="8dp"
android:text="The food test was very good."
android:textColor="@color/black"
android:textColorHint="@color/hint_text_color" />
</TableRow>
How to let a TextView have multiple lines?
It sounds like you want to wrap text around a picture, like so:
--------------------
|..........| xxxxxxx
|..Picture.| xxxxxxx
|..........| xxxxxxx
------------ xxxxxxx
xxxxxxxxxxTextxxxxxx
xxxxxxxxxxxxxxxxxxxx
I think the easiest option is to a WebView. However, according to this you can also use image tags in a TextView. I've never tried it myself, but I have used the other tags like so: TextView.setText(Html.fromHtml("<b>some bold text</b> some normal text"))
so maybe something similar will work in your situation.
Forcing a TextView to be with a multiple line text
Use the below layout I have mentioned in comments too.
<LinearLayout
android:id="@+id/linearLayoutBottomData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayoutTopData"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="@+id/myTextView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:gravity="left|start"
android:text="TextView"
android:textColor="@android:color/black"
android:textSize="@dimen/large_font_size"
android:singleLine="false"/>
<TextView
android:id="@+id/myTextView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:gravity="left|start"
android:text="TextView"
android:textColor="@android:color/black"
android:textSize="@dimen/large_font_size"/>
How to make a TextView multiline programmatically in Android (Java)
You want to show to different texts in the same textview? if so, use two text views like:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</LinearLayout>
Remote android:inputType="textMultiLine", this is an EditText Atribute.
If you just want to use more then one line in the same text view:
android:maxLines="5"//optional to set max numbers of lines
android:minLines="2"//optional to set min numbers of lines
android:singleLine="false"//set false to allow multiple line
android:lines="2" //or more
If this textview you want to use belongs to a ListView, just use:
android.R.layout.simple_list_item_2
It will give you two texts views to work on.
Creating a multiline TextView
try following for multiline TextView.
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLines="4"
android:singleLine="false"
android:text="YES\nNo\ntrue\nfalse" />
You can try \n
to set text in next line.
Android TextView Multiline Formatting
For me the correct answer, and actually so simple I should have discovered earlier:
I simply added:
android:typeface="monospace"
to my TextView
How to set a Multiline-TextView non-editable
Try this make you TextView
to android:longClickable="false"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1. Hello, Dies ist ein Beispielsatz. \n2. Dies ist der zweite Satz."
android:longClickable="false"
android:textSize="20dp"
android:inputType="textMultiLine"
/>
Multiline TextView with line breaks wrapping
Muhammad Babar's suggestion fixes the issue. I added a RelativeLayout as the parent of the LinearLayout and now all text is properly shown (see below for working code).
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:orientation="vertical">
<ImageView
android:id="@+id/OfficeImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center_horizontal"
android:scaleType="centerInside"
android:adjustViewBounds="true"
android:maxWidth="175dp"/>
<TextView
android:layout_marginTop="10dp"
android:id="@+id/InfoWindowTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sunshine Coast"
android:textColor="@android:color/black"
android:textStyle="bold"/>
<TextView
android:id="@+id/InfoWindowSubtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10dp"
android:text="Level 3, 2 Emporio Place\n2 Maroochy Blvd, Maroochydore QLD 4558\nPo Box 5800, Maroochydore BC QLD 4558"
android:maxLines="10"
android:textColor="@android:color/black"/>
</LinearLayout>
</RelativeLayout>
Related Topics
Android Gradle Error When Sync Style Attribute Not Found
Android Volley Basicnetwork.Performrequest() Unexpected Response Code 404
Gradle Error: Could Not Execute Build Using Gradle Distribution
How to Fix Attempt to Invoke Interface Method on a Null Object Reference
How to Start Android Application on Device Boot
How to Show the Number Keyboard on an Edittext in Android
How to Delete Shared Preferences Data from App in Android
Recyclerview Cannot Be Scrolled
Android: How to Propagate Click Event to Linearlayout Childs and Change Their Drawable
Retrofit2 - How to Upload Image Using Retrofit in Multipart
Download Manager Progress Not Visible in the Notification Area
How Disable Redirect in Webview
Removing Backgroundcolor of a View in Android
Android: Rotate Image in Imageview by an Angle
How to Make Service That Is Unremovable Even If Killed by the System