换行时如何隐藏文本? [英] How to hide the text when wrapping?

查看:34
本文介绍了换行时如何隐藏文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这篇关于换行时如何隐藏文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆