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条回答
Emotional °昔
2楼-- · 2020-02-10 18:04

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?"

查看更多
登录 后发表回答