How to set maximum characters per line for text vi

2020-02-10 17:26发布

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.

标签: android
7条回答
Anthone
2楼-- · 2020-02-10 17:47

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

查看更多
贼婆χ
3楼-- · 2020-02-10 17:49

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.

查看更多
太酷不给撩
4楼-- · 2020-02-10 17:53

Use this code:

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

Five line with max length of 10 character.

查看更多
甜甜的少女心
5楼-- · 2020-02-10 17:55

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

查看更多
家丑人穷心不美
6楼-- · 2020-02-10 17:58

Use this android:maxLength="10"

For more Information refer this site

查看更多
一夜七次
7楼-- · 2020-02-10 18:01

Using

android:maxWidth="size"

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

查看更多
登录 后发表回答