1

我有一个简单的RecyclerView使用 2 个字符串。一旦第二个TextView获得多行文本,它就会被剪掉,而不是仅仅扩大视图的高度。

在此处输入图像描述

例如,两个 textView 收到的文本是:

"Director":"Cate Shortland"
"Writer":"Jac Schaeffer (story by), Ned Benson (story by), Eric Pearson (screenplay by), Stan Lee (based on the Marvel comics by), Don Heck (based on the Marvel comics by), Don Rico (based on the Marvel comics by)"

我的观点:

<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"
    android:id="@+id/layout">

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/textview"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="@+id/detial"
        app:layout_constraintStart_toEndOf="@+id/detial" />

    <TextView
        android:id="@+id/detial"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="18dp"
        android:maxWidth="250dp"
        android:text="@string/year"
        android:maxLines="24"
        android:textSize="18sp"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout> 

我尝试从更改wrap_contentmatch_parent,添加android:inputType="textMultiLine"并检查它RecyclerView是最新版本(因为早期版本有一些错误)。有什么我可以尝试的想法吗?

4

2 回答 2

1
<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"
android:id="@+id/layout">

<TextView
    android:id="@+id/detial"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="18dp"
    android:maxWidth="250dp"
    android:text="@string/year"
    android:maxLines="24"
    android:textSize="18sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toStartOf="@+id/name"
    app:layout_constraintHorizontal_chainStyle="packed"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/name"
    android:layout_width="@dimen/match_constraint"
    android:layout_height="wrap_content"
    android:text="text"
    android:textSize="18sp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/detial" />

</androidx.constraintlayout.widget.ConstraintLayout> 
于 2020-05-25T15:10:06.643 回答
0

将您的 textview 宽度更改为match_parent

它适用于您的文本内容

<TextView
    android:id="@+id/detial"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="18dp"
    android:maxWidth="250dp"
    android:text="Jac Schaeffer (story by), Ned Benson (story by), Eric Pearson (screenplay by), Stan Lee (based on the Marvel comics by), Don Heck (based on the Marvel comics by), Don Rico (based on the Marvel comics by)"
    android:maxLines="24"
    android:textSize="18sp"
    app:layout_constraintHorizontal_chainStyle="packed"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
于 2020-05-25T15:04:17.090 回答