ConstraintLayout不会在TextView中省略长文本 [英] ConstraintLayout does not ellipsize long text in TextView
本文介绍了ConstraintLayout不会在TextView中省略长文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在图像的右侧有一个TextView
.我正在尝试在图像旁边放置一些长文本,但此文本应通过在末尾添加"..."自动结束.但是,这不起作用.我使用这种布局:
I have a TextView
to the right of an image. I am trying to place some long text next to the image but this text should automatically end by adding "..." at the end. However, this does not work. I use this layout:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp">
<ImageView
android:id="@+id/file_icon"
android:layout_width="250px"
android:layout_height="250px"
android:layout_gravity="center"
android:clickable="true"
android:scaleType="centerInside"
android:src="@drawable/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/file_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="This is a very long title and I hope I have the dots to break it"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/file_type"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintStart_toEndOf="@+id/file_icon"
app:layout_constraintWidth_default="wrap"/>
<TextView
android:id="@+id/file_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Type"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/file_title"
app:layout_constraintLeft_toRightOf="@+id/file_icon" />
<ImageView
android:id="@+id/file_download"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:clickable="true"
android:scaleType="centerInside"
android:src="@drawable/ic_action_download"
app:layout_constraintTop_toBottomOf="@+id/file_title"
app:layout_constraintRight_toRightOf="parent" />
结果是这样的:
为什么长文本不为椭圆形,以致在末尾出现"..."?我已阅读此和
Why does the long text not ellipsize such that "..." appears at the end? I have read this and this post but it does not work for me. Can anyone help me here?
推荐答案
对您的 file_title
TextView
尝试一下
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp">
<ImageView
android:id="@+id/file_icon"
android:layout_width="250px"
android:layout_height="250px"
android:layout_gravity="center"
android:clickable="true"
android:scaleType="centerInside"
android:src="@drawable/abc"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/file_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="This is a very long title and I hope I have the dots to break it"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintBottom_toTopOf="@+id/file_type"
app:layout_constraintStart_toEndOf="@+id/file_icon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintEnd_toEndOf="parent"
/>
<TextView
android:id="@+id/file_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Type"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/file_icon"
app:layout_constraintTop_toBottomOf="@+id/file_title" />
<ImageView
android:id="@+id/file_download"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:clickable="true"
android:scaleType="centerInside"
android:src="@drawable/abc"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/file_title" />
</android.support.constraint.ConstraintLayout>
输出
这篇关于ConstraintLayout不会在TextView中省略长文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文