Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wrap text to next line in an Android TextView?

I am using following TextView to display some data in it:

<TextView android:id="@+id/notificationText" 
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:textSize="18sp"
        android:inputType="textMultiLine"
        android:maxLines="2"
        android:layout_paddingRight="20dip"
        android:textColor="#ffffff"/>

I want to wrap text to next line. How can I do this?

like image 969
UMAR-MOBITSOLUTIONS Avatar asked Nov 11 '10 08:11

UMAR-MOBITSOLUTIONS


People also ask

How do I make text go to the next line in android?

for the new line in TextView just add \n in middle of your text it works..

How do I add a line break in android?

Add Line Breaks to a TextView Just add a \n to your text. This can be done directly in your layout file, or in a string resource and will cleanly break the text in your TextView to the next line.

Can we Nest TextView inside TextView?

In Android all layout can be nested one another.


3 Answers

you must set android:scrollHorizontally="false" in your xml.

like image 140
Paresh Mayani Avatar answered Oct 09 '22 22:10

Paresh Mayani


In Some case It works by setting width to 0dp on text views.

android:layout_width="0dp"

here is a link to original answer.

like image 18
vikas kumar Avatar answered Oct 09 '22 22:10

vikas kumar


You could also try

android:inputType="textMultiLine"

in your XML. This worked for me.

like image 12
remykarem Avatar answered Oct 10 '22 00:10

remykarem