TextView 属性 'android:maxLength' 不适用于 'android:maxLines'



我有一个 TextView,定义如下:

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:maxLength="25"
        android:gravity="center"
        android:maxLines="5"
        android:singleLine="false" />

但是,这将导致一条线,而不是末尾有3个点的5行。maxLength值25个作品,但它可以将视图锁定为一行。

我如何实现对字符数量的约束,但同时也对行的数量也有限制?

使用以下代码。它将为您提供帮助。

        <TextView
            android:id="@+id/tvTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Sample title"
            android:maxLines="5"
            android:lines="5"
        android:textSize="20dp"/>

我想你想在textview

中添加多行

使用线路属性,使其水平不可扣(如果需要),并从视图的启动开始。

android:gravity="start"
android:scrollHorizontally="false"
android:lines="5"

相关内容

最新更新