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 display the remaining characters in the next line.I cannot set ems value and I also tried setting maxLength attribute in xml but it is not displaying the remaining characters,Can any one tell me how can I do it.
Asked
Active
Viewed 3.3k times
6 Answers
36
Using
android:maxWidth="size"
Replace the "size" with the size you prefer. For example, 100dip
.

prolink007
- 33,872
- 24
- 117
- 185
-
doesn't work if layout_width is set to wrap_content? – Lendl Leyba Oct 01 '16 at 09:03
2
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

Thkru
- 4,218
- 2
- 18
- 37
1
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.

Jacek
- 464
- 4
- 9
1
use ConstraintLayout and android:layout_width="0dp". The text will adapt to the constraints

Dan Alboteanu
- 9,404
- 1
- 52
- 40
-3
Use this code:
android:maxLines="5"
android:maxLength="10"
Five line with max length of 10 character.

Ganesh Katikar
- 2,620
- 1
- 26
- 28
-
1This adds nothing to http://stackoverflow.com/a/10933498/525478, which is more complete and over 2 years old... – Brad Werth Sep 27 '14 at 08:02