ConstraintLayout TextView обрезка текста - PullRequest
2 голосов
/ 17 апреля 2019

У меня странная проблема, когда текст в TextView не отображается, если он переносится на новую строку.

Этот снимок экрана показывает мою проблему:

enter image description here

Текст, выделенный жирным шрифтом, переносит слово на следующую строку, но не отображается.Вот как это выглядит без жирного шрифта:

enter image description here

И это то, на что это похоже, если я форсирую две строки, используя android:lines="2": enter image description here

Это код, который я использую:

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

Я пытался установить width на wrap_content и изменить отступы и поляно ничего не работает.

Я должен упомянуть, что этот макет представляет собой строку в RecyclerView, если это имеет значение.

1 Ответ

0 голосов
/ 17 апреля 2019
<?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>

Попробуйте использовать приведенный выше макет с правильными чертежами

...