Textview maxLines ellipsize 属性失效

2021-08-25  本文已影响0人  房房1524

1、问题&代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/ln_message_parent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tvLine"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxHeight="40dp"
        android:minHeight="20dp"
        android:includeFontPadding="false"
        android:maxLines="2"
        android:gravity="center|start"
        android:lineSpacingExtra="1dp"
        android:textColor="@color/white"
        android:textSize="@dimen/textSize14dp"
        android:ellipsize="end"
        tools:text="1222222222"
        tools:textColor="@color/black_trans40"
        tools:ignore="SpUsage" />
</LinearLayout>

2、解决方法
属性失效,需要将parent的高度限制为textview 最大高度,属性就正常了。

3、为什么
猜测:maxLines是通过限制高度实现的,如果父元素高度不固定(wrap_content),maxlines会失效。

4、有时间看代码验证一下

上一篇 下一篇

猜你喜欢

热点阅读