ConstraintLayout TextView cutting text off

时间:2019-04-16 23:51:34

标签: android textview android-constraintlayout

I have a strange problem where the text in a TextView is not being displayed if it's wrapping to a new line.

This screenshot shows my issue:

enter image description here

The bold text is causing a word to wrap to the next line but it's not being shown. This is what it looks like without the bold:

enter image description here

And this is what it looks like if I force two lines using android:lines="2": enter image description here

This is the code I'm using:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/episode_row_item_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:padding="5dp"
    android:foreground="?android:attr/selectableItemBackground"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/episode_row_item_title_thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:visibility="gone"
        />
    <!-- This is the problematic textview-->
    <TextView
        android:id="@+id/episode_row_item_title"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:lineSpacingExtra="2dp"
        android:layout_marginEnd="8dp"
        android:breakStrategy="simple"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/episode_row_item_download"
        android:foreground="?android:attr/selectableItemBackground"
       />

    <ImageView
        android:id="@+id/episode_row_item_download"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="2dp"
        app:layout_constraintTop_toTopOf="@+id/episode_row_item_title"
        app:layout_constraintEnd_toEndOf="parent"
        android:foreground="?android:attr/selectableItemBackground"
        />

    <TextView
        android:id="@+id/episode_row_item_date"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:textSize="13sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/episode_row_item_title"
        app:layout_constraintEnd_toStartOf="@+id/episode_row_item_duration"
        android:layout_marginTop="4dp"
        />

    <TextView
        android:id="@+id/episode_row_item_duration"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="13sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/episode_row_item_title"
        android:layout_marginTop="4dp"
        />

</androidx.constraintlayout.widget.ConstraintLayout>

I've tried setting the width to wrap_content and changing the padding and margins but nothing works.

I should mention this layout is a row in a RecyclerView if that makes a difference.

1 个答案:

答案 0 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/episode_row_item_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp"
    android:foreground="?android:attr/selectableItemBackground">

    <ImageView
        android:id="@+id/episode_row_item_title_thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:visibility="visible"
        />
    <!-- This is the problematic textview-->
    <TextView
        android:id="@+id/episode_row_item_title"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:lineSpacingExtra="2dp"
        android:layout_marginEnd="8dp"
        android:textStyle="bold"
        android:text="Episode 1010 Christina Hendericks"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/episode_row_item_title_thumbnail"
        app:layout_constraintEnd_toStartOf="@+id/episode_row_item_download"
        android:foreground="?android:attr/selectableItemBackground"
        android:layout_marginRight="8dp"/>

    <ImageView
        android:id="@+id/episode_row_item_download"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="2dp"
        app:layout_constraintTop_toTopOf="@+id/episode_row_item_title"
        app:layout_constraintEnd_toEndOf="parent"
        android:foreground="?android:attr/selectableItemBackground"
        />

    <TextView
        android:id="@+id/episode_row_item_date"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:textSize="13sp"
        app:layout_constraintStart_toStartOf="parent"
        android:text="Yesterday"
        app:layout_constraintTop_toBottomOf="@+id/episode_row_item_title"
        app:layout_constraintEnd_toStartOf="@+id/episode_row_item_duration"
        android:layout_marginTop="4dp"/>

    <TextView
        android:id="@+id/episode_row_item_duration"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="13sp"
        android:text="01:02:24"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/episode_row_item_download"
        android:layout_marginTop="4dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

尝试将上述布局与正确的可绘制对象一起使用