How to make TextView multi-line programmatically in Android (Java)

I want to make my text file multi-line.

Image: http://s13.postimg.org/y0q78e1yv/Capture.png

But how can I make my text multiline?

What attribute?

TextView txt_tweet = (TextView) View.inflate(this, R.layout.special_textview, null); 

special_textview

  <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="wrap_content" android:paddingLeft="20dp" android:paddingRight="20dp" android:paddingBottom="5dp" android:inputType="textMultiLine" android:scrollHorizontally="false"> </TextView> 
+5
source share
8 answers

Do you want to display different texts in the same text form? if so, use two text views, for example:

 <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 attribute of EditText.

If you just want to use more than one line in the same text form:

 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 text view that you want to use belongs to the ListView, simply use:

 android.R.layout.simple_list_item_2 

This will give you two texts to work on.

+3
source

You can do it as follows:

 txt_tweet.setSingleLine(false); txt_tweet.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION); 
+1
source

I did it as follows:

 tv.setElegantTextHeight(true); tv.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE); tv.setSingleLine(false); 
+1
source

First replace " \n " with your Html equivalent " &lt;br&gt; " and then call Html.fromHtml() on the line. Follow these steps:

 String text= model.getMessageBody().toString().replace("\n", "&lt;br&gt;") textView.setText(Html.fromHtml(Html.fromHtml(text).toString())) 

This works great.

+1
source

TextView should have the 'singleLine' attribute set to false. You must also set "ellipsize" to wrap the text:

 android:singleLine="false" android:ellipsize="end" 
0
source

in layout

 android:lines="8" //Total Lines prior display android:minLines="6" //Minimum lines android:maxLines="10" //Maximum Lines 
0
source

Addendum to the answers: order matters!

Make sure you call setInputType before setMinLines!

0
source

Just delete this line:

  android:inputType="textMultiLine" 

inputType for EditTexts

-1
source

All Articles