gpt4 book ai didi

android - ConstraintLayout 不会省略 TextView 中的长文本

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:07:33 25 4
gpt4 key购买 nike

我在图像右侧有一个 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/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" />

结果是这样的:

enter image description here

为什么长文本不是椭圆形的,以至于“...”出现在末尾?我读过thisthis发布,但它对我不起作用。有人可以帮我吗?

最佳答案

app:layout_constraintEnd_toEndOf="parent" 用于您的 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>

输出

enter image description here

关于android - ConstraintLayout 不会省略 TextView 中的长文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50035570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com