TextView too long and exceeds screen

I have this text view that when it’s too long it exceeds the screen (works well otherwise). I tried fixing it with:

android:layout_width="wrap_content"
app:layout_constrainedWidth="true"

And:

android:ellipsize="end"
android:maxLines="2"

That doesn’t do anything, though, and whenever the text is too long, I cannot see all of it on my screen. So how do I fix it?

This is the xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/blue_700">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/movie_detail"
        android:layout_width="match_parent"
        android:background="#6B3C3D40"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/iv_poster_detail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingStart="8dp"
            android:paddingEnd="8dp"
            android:paddingTop="8dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:src="@drawable/ic_launcher_background" />

        <TextView
            android:id="@+id/tv_title_detail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="@string/movie_title"
            android:maxLines="3"
            android:paddingStart="10dp"
            android:paddingTop="8dp"
            android:paddingEnd="10dp"
            android:paddingBottom="8dp"
            android:textColor="#EA4B00"
            android:textSize="25sp"
            app:layout_constraintStart_toEndOf="@+id/iv_poster_detail"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/tv_overview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/movie_description"
            android:textColor="@color/white"
            android:textSize="15sp"
            android:paddingStart="15dp"
            android:paddingEnd="15dp"
            android:paddingTop="20dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/iv_poster_detail" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</FrameLayout>

Answer

Widgets dimension constraints

Using 0dp, which is the equivalent of “MATCH_CONSTRAINT”

Try with this:

 <TextView
            android:id="@+id/tv_title_detail"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:hint="Sed ut perspiciatis unde omnis iste natus er"
            android:maxLines="3"
            android:paddingStart="10dp"
            android:paddingTop="8dp"
            android:paddingEnd="10dp"
            android:paddingBottom="8dp"
            android:textColor="#EA4B00"
            android:textSize="25sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/iv_poster_detail"
            app:layout_constraintTop_toTopOf="@+id/iv_poster_detail" />

enter image description here

Reference