换行时如何隐藏文本?

问题描述:

<TextView
        android:layout_marginLeft="12dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:id="@+id/tvVExample"
        android:textColor="#496933"
        android:singleLine="false"
        android:textStyle="bold"
        android:textSize="16sp"/>

例如文字为:

Having desirable or positive qualities especially those suitable for a thing specified

它向我展示了:

Having desirable or positive qualities especially those suita
specified

它可以包装.它显示了两行,但隐藏了一些单词

It can wrap. And It shows two lines but some words is hidden

我的预期是:

Having desirable or positive qualities especially those 
suitable for a thing specified

最后我找到了解决方案,如果 TextView 是 GridLayout 的子项.我无法将宽度设置为 WRAP_CONTECT,因为它将使用整行作为宽度而不是单元格的宽度.解决方案是将宽度设置为 0dp,并将 layout_gravity 设置为 fill_horizo​​ntal.此外,gridlayout 的宽度必须为 MATCH_PARENT.

Finally I find the solution, if the TextView which is the child of GridLayout. I can't set the width to WRAP_CONTECT becacuse it will use the whole row as the width but not the width of the cell. The solution is that set the width to 0dp and set the layout_gravity to fill_horizontal. Also, the width of the gridlayout must be MATCH_PARENT.

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:columnCount="3"
            android:orientation="horizontal">
.
.
.

<TextView
    android:layout_marginLeft="12dp"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_gravity="fill_horizontal"
    android:text="New Text"
    android:id="@+id/tvVExample"
    android:textColor="#496933"
    android:textStyle="bold"
    android:textSize="16sp"/>
.
.
.
</GridLayout>