Does any one know how to wrap text in TextView in Android platform. i.e if the text in textview exceed the screen length it should be displayed in the second line.
I
Try @Guykun's approach
android:layout_weight="1"
android:ellipsize="none"
android:maxLines="100"
android:scrollHorizontally="false"
Also, make sure that parents width is not set to wrap content. This is the thing that I was missing.
Just was working on a TextView inside a layout inside a RecyclerView. I had text getting cut off, ex, for Read this message
, I saw: Read this
. I tried setting android:maxLines="2"
on the TextView, but nothing changed. However, android:lines="2"
resulted in Read this
on first line and message
on the 2nd.
The trick is with the textView width, try to make it dedicated number like:
<TextView
android:layout_width="300dp"
android:layout_height="wrap_content"/>
I've tried many solutions without any result, I've tried:
android:ellipsize="none"
android:scrollHorizontally="false"
the only one thing triggred the wrap option is the dedicated width
I am using Android 2.2 and my textview will automatically goto the next line if it exceeds the screen.
If you would like to have the text goto the next line before the end of the screen, just add in (just put in your own dp value). This will be useful if you have a picture on the right of the text.
android:layout_marginRight="52dp"
<TextView
android:id="@+id/some_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="@id/textview_above"
app:layout_constraintRight_toLeftOf="@id/button_to_right"/>
android:maxLines="2"
to prevent vertical expansion (2 is just an e.g.)android:ellipsize="end"
0dp width allows left/right constraints to determine how wide your widget is.
Setting left/right constraints sets the actual width of your widget, within which your text will wrap.
Constraint Layout docs
By setting android:maxEms
to a given value together with android:layout_weight="1"
will cause the TextView to wrap once it reaches the given length of the ems.