Search code examples
androidandroid-recyclerviewtextviewandroid-wrap-content

Why does my text get cut out as soon as it hits multiple lines?


I have a simple RecyclerView using 2 strings. As soon as the 2nd TextView gets multiple lines of text, it gets cut out instead of just expanding the height of the view.

enter image description here

For example the text that two textViews received was:

"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)"

My view:

<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> 

I tried changing from wrap_content to match_parent, adding android:inputType="textMultiLine" and checked that the RecyclerView is the latest version (because of some bug that earlier versions had). Any ideas what I could try out?


Solution

  • <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>