Java – How to make a TextView multiline programmatically in Android (Java)

androidjavamultilinetextview

I want to make my textview multiline.

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

But how can I make my text multiline ?

Which atribut ?

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>

Best Solution

I did it following way:

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