Hiii all, this may be a possible duplicate but I couldn\'t find solution for my problem.I need to limit the number of characters per line when displaying on the textview and
use android:maxWidth="10dip"
to limit the size of the textview.
With this limitation the next line (assume you used setSingleLine(false)
) will start right after the 10dip
.
Using android:maxLength="50"
for example would limit your textview, but doesn't ensure that it breaks after X characters
Set these parameters of TextView:
android:layout_width="110dip"
android:singleline="false"
Experiment with the value of android:layout_width
to find the value that fits your needs.
Use android:maxLength=""
to limit the text length
<TextView
android:id="@+id/textViewName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="Name"
android:maxLength="12"
android:textColor="#000000"
android:textStyle="bold" />
You can also use another property as follows:
android:ellipsize="end"
android:maxLines="1"
show result :
"Hello How are ..." instead of "Hello How are you?"
Using
android:maxWidth="size"
Replace the "size" with the size you prefer. For example, 100dip
.
use ConstraintLayout and android:layout_width="0dp". The text will adapt to the constraints
Use this code:
android:maxLines="5"
android:maxLength="10"
Five line with max length of 10 character.