Почему часть текста находится за экраном?

У меня следующая проблема: часть текста в textview находится за экраном

Почему часть текста находится за экраном?

Я не понимаю, почему это происходит, как обычно, когда я использую wrap_content текст имеет несколько строк, и все они на экране. Я добавил android:layout_marginEnd = "16dp" ко всем текстовым представлениям, но все равно возникает та же проблема. Вот файл xml со всеми этими текстовыми представлениями:

<?xml version = "1.0" encoding = "utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    tools:context = ".FilmDetailActivity">

    <ImageView
        android:id = "@+id/avatar_imageview"
        android:layout_width = "150dp"
        android:layout_height = "250dp"
        android:layout_marginStart = "8dp"
        android:layout_marginTop = "8dp"
        android:layout_marginEnd = "16dp"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toTopOf = "parent"
        tools:ignore = "ContentDescription" />

    <TextView
        android:id = "@+id/title_textview"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginTop = "8dp"
        android:layout_marginStart = "16dp"
        android:layout_marginEnd = "16dp"
        app:layout_constraintStart_toEndOf = "@id/avatar_imageview"
        app:layout_constraintTop_toTopOf = "parent"/>

    <TextView
        android:id = "@+id/year_textview"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginTop = "16dp"
        android:layout_marginStart = "16dp"
        android:layout_marginEnd = "16dp"
        android:text = "@string/year"
        app:layout_constraintStart_toEndOf = "@id/avatar_imageview"
        app:layout_constraintTop_toBottomOf = "@id/title_textview"/>

    <TextView
        android:id = "@+id/runtime_textview"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginTop = "16dp"
        android:layout_marginStart = "16dp"
        android:layout_marginEnd = "16dp"
        android:text = "@string/runtime"
        app:layout_constraintStart_toEndOf = "@id/avatar_imageview"
        app:layout_constraintTop_toBottomOf = "@id/year_textview"/>

    <TextView
        android:id = "@+id/director_textview"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginTop = "16dp"
        android:layout_marginStart = "16dp"
        android:layout_marginEnd = "16dp"
        android:text = "@string/director"
        app:layout_constraintStart_toEndOf = "@id/avatar_imageview"
        app:layout_constraintTop_toBottomOf = "@id/runtime_textview"/>

    <TextView
        android:id = "@+id/actors_textview"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginTop = "16dp"
        android:layout_marginStart = "16dp"
        android:layout_marginEnd = "16dp"
        android:text = "@string/actors"
        app:layout_constraintStart_toEndOf = "@id/avatar_imageview"
        app:layout_constraintTop_toBottomOf = "@id/director_textview"/>

    <TextView
        android:id = "@+id/plot_textview"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginTop = "16dp"
        android:layout_marginStart = "16dp"
        android:layout_marginEnd = "16dp"
        android:text = "@string/plot"
        app:layout_constraintStart_toEndOf = "@id/avatar_imageview"
        app:layout_constraintTop_toBottomOf = "@id/actors_textview" />

    <TextView
        android:id = "@+id/language_textview"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginTop = "16dp"
        android:layout_marginStart = "16dp"
        android:layout_marginEnd = "16dp"
        android:text = "@string/language"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toBottomOf = "@id/plot_textview" />

    <TextView
        android:id = "@+id/country_textview"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginStart = "16dp"
        android:layout_marginTop = "16dp"
        android:layout_marginEnd = "16dp"
        android:text = "@string/country"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toBottomOf = "@id/language_textview" />

    <TextView
        android:id = "@+id/imdb_rating_textview"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginTop = "16dp"
        android:layout_marginStart = "16dp"
        android:layout_marginEnd = "16dp"
        android:text = "@string/imdb_rating"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toBottomOf = "@id/country_textview"/>

</android.support.constraint.ConstraintLayout>

Итак, почему эта проблема возникает и как я могу ее решить?

УПД

Когда я добавил app:layout_constraintEnd_toEndOf = "parent" к каждому TextView, я столкнулся со следующей проблемой:

Почему часть текста находится за экраном?

УПД 2

Когда я добавил app:layout_constraintHorizontal_bias = "0" я обнаружил ту же проблему, что и раньше

Почему часть текста находится за экраном?

Настройте свои TextViews как многострочные. Используйте android:maxLines = "4", чтобы обозначить максимальное количество строк, которые можно использовать при необходимости, и используйте android:lines = "4", чтобы текст отображался в 4 строки. Посмотрите, поможет ли это.

MD Naseem Ashraf 21.04.2019 16:44
1
1
37
2
Перейти к ответу Данный вопрос помечен как решенный

Ответы 2

Ответ принят как подходящий

Измените layout_width = "wrap_content" на layout_width = "0dp" в ваших текстовых представлениях.

Добавьте app:layout_constraintEnd_toEndOf = "parent" к своим TextView, чтобы убедиться, что они вписываются в макет.

Кроме того, если ваш текст выравнивается по центру, добавьте app:layout_constraintHorizontal_bias = "0", чтобы выровнять его по левому краю ("1" для выравнивания по правому краю)

Обновил вопрос

Sergei Mikhailovskii 21.04.2019 16:21

Измените layout_width = "wrap_content" на layout_width = "0dp" в ваших текстовых просмотрах

solidogen 21.04.2019 16:37

Добавьте app:layout_constraintEnd_toEndOf = "parent" (правое ограничение) в TextView и установите layout_width на 0dp

Вот обновленная версия вашего макета


<?xml version = "1.0" encoding = "utf-8"?>
<android.support.constraint.ConstraintLayout 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">

    <ImageView
        android:id = "@+id/avatar_imageview"
        android:layout_width = "150dp"
        android:layout_height = "250dp"
        android:layout_marginStart = "8dp"
        android:layout_marginLeft = "8dp"
        android:layout_marginTop = "8dp"
        android:layout_marginEnd = "16dp"
        android:layout_marginRight = "8dp"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toTopOf = "parent"
        tools:ignore = "ContentDescription" />

    <TextView
        android:id = "@+id/title_textview"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginStart = "16dp"
        android:layout_marginTop = "8dp"
        android:layout_marginEnd = "16dp"
        app:layout_constraintStart_toEndOf = "@id/avatar_imageview"
        app:layout_constraintTop_toTopOf = "parent" />

    <TextView
        android:id = "@+id/year_textview"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginStart = "16dp"
        android:layout_marginTop = "16dp"
        android:layout_marginEnd = "16dp"
        android:text = "2017"
        app:layout_constraintStart_toEndOf = "@id/avatar_imageview"
        app:layout_constraintTop_toBottomOf = "@id/title_textview" />

    <TextView
        android:id = "@+id/runtime_textview"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginStart = "16dp"
        android:layout_marginTop = "16dp"
        android:layout_marginEnd = "16dp"
        android:text = "2 hours 1 minute"
        app:layout_constraintStart_toEndOf = "@id/avatar_imageview"
        app:layout_constraintTop_toBottomOf = "@id/year_textview" />

    <TextView
        android:id = "@+id/director_textview"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginStart = "16dp"
        android:layout_marginTop = "16dp"
        android:layout_marginEnd = "16dp"
        android:text = "Mr James Collon"
        app:layout_constraintStart_toEndOf = "@id/avatar_imageview"
        app:layout_constraintTop_toBottomOf = "@id/runtime_textview" />

    <TextView
        android:id = "@+id/actors_textview"
        android:layout_width = "0dp"
        android:layout_height = "wrap_content"
        android:layout_marginStart = "16dp"
        android:layout_marginTop = "16dp"
        android:layout_marginEnd = "16dp"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintStart_toEndOf = "@id/avatar_imageview"
        app:layout_constraintTop_toBottomOf = "@id/director_textview" />

    <TextView
        android:id = "@+id/plot_textview"
        android:layout_width = "0dp"
        android:layout_height = "wrap_content"
        android:layout_marginStart = "16dp"
        android:layout_marginTop = "16dp"
        android:layout_marginEnd = "16dp"
        android:text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged."
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintStart_toEndOf = "@id/avatar_imageview"
        app:layout_constraintTop_toBottomOf = "@id/actors_textview" />

    <TextView
        android:id = "@+id/language_textview"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginStart = "16dp"
        android:layout_marginTop = "16dp"
        android:layout_marginEnd = "16dp"
        android:text = "English"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toBottomOf = "@id/plot_textview" />

    <TextView
        android:id = "@+id/country_textview"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginStart = "16dp"
        android:layout_marginTop = "16dp"
        android:layout_marginEnd = "16dp"
        android:text = "India"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toBottomOf = "@id/language_textview" />

    <TextView
        android:id = "@+id/imdb_rating_textview"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginStart = "16dp"
        android:layout_marginTop = "16dp"
        android:layout_marginEnd = "16dp"
        android:text = "7/10"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toBottomOf = "@id/country_textview" />

</android.support.constraint.ConstraintLayout>

ПРИМЕЧАНИЕ. В демонстрационных целях исправление было внесено только в текстовое представление plot. Пожалуйста, сделайте то же самое и для других текстовых представлений.

Другие вопросы по теме