<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
它可以包裹。它显示两行但隐藏了一些单词
我期望的是:
Having desirable or positive qualities especially those
suitable for a thing specified
最佳答案
最后我找到了解决方案,如果 TextView 是 GridLayout 的子项。我无法将宽度设置为 WRAP_CONTECT 因为它将使用整行作为宽度而不是单元格的宽度。解决方案是将宽度设置为 0dp,将 layout_gravity 设置为 fill_horizontal。此外,网格布局的宽度必须为 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>
关于android - 换行时如何隐藏文字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16995681/