我知道有很多类似的问题,我也阅读了很多答案,但没有一个是我想要的。我几乎都试过了。以下是我的尝试(我ellipsize=end
为每次尝试设置):
singleLine=true
(作品)lines=1
(不行)maxLines=1
(不行)- 将 textView 的宽度设置为特定值(不起作用)
ScrollHorizontally=true
(不行)
只有第一个有效,但我想要多行文本而不是一行
有没有其他方法可以实现这一点
任何帮助将不胜感激
编辑:
这是我的 xml 布局(尝试 2):
<androidx.constraintlayout.widget.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">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="@dimen/x150"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:ellipsize="end"
android:lines="1"
android:text="hello hello hello hello hello hello hello hello hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/image" />
</androidx.constraintlayout.widget.ConstraintLayout>