dharan
dharan

Reputation: 753

How to set maximum characters per line for text view in android

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.

Upvotes: 15

Views: 34449

Answers (6)

Aerrow
Aerrow

Reputation: 12134

Use this android:maxLength="10"

For more Information refer this site

Upvotes: 3

Dan Alboteanu
Dan Alboteanu

Reputation: 10232

use ConstraintLayout and android:layout_width="0dp". The text will adapt to the constraints

Upvotes: 1

Ganesh Katikar
Ganesh Katikar

Reputation: 2690

Use this code:

android:maxLines="5"
android:maxLength="10"

Five line with max length of 10 character.

Upvotes: -3

Thkru
Thkru

Reputation: 4199

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

Upvotes: 2

Jacek
Jacek

Reputation: 474

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.

Upvotes: 1

prolink007
prolink007

Reputation: 34544

Using

android:maxWidth="size"

Replace the "size" with the size you prefer. For example, 100dip.

Upvotes: 36

Related Questions