android - 为什么部分文本位于屏幕后面?

标签 android xml textview

我有以下问题:textview 中的部分文本位于屏幕后面

enter image description here

我不明白为什么当我使用 wrap_content 文本时通常会发生这种情况,文本有几行并且所有行都在屏幕上。我将 android:layout_marginEnd="16dp" 添加到所有 TextView ,但仍然出现同样的问题。这是包含所有这些 TextView 的 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>

那么,为什么会出现这个问题,我该如何解决呢?

UPD

当我将 app:layout_constraintEnd_toEndOf="parent" 添加到每个 TextView 时,我遇到了以下问题:

enter image description here

UPD 2

当我添加 app:layout_constraintHorizo​​ntal_bias="0" 时,我发现了同样的问题,这是之前的

enter image description here

最佳答案

在您的 TextView 中将 layout_width="wrap_content" 更改为 layout_width="0dp"

app:layout_constraintEnd_toEndOf="parent" 添加到您的 TextView 以确保它们适合布局

此外,如果您的文本居中对齐 - 添加 app:layout_constraintHorizo​​ntal_bias="0" 使其向左对齐(“1”表示右对齐)

关于android - 为什么部分文本位于屏幕后面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55783440/

相关文章:

Android 从 GridView 中的 EditText 获取文本

android - 如何在 TextView 周围设置阴影

android - 有谁知道 AIR 是否支持 iOS 或 Android 上的本地多人游戏?

android - 如何调试从 Flutter Pllatform Channel 调用的原生 Android

java - Android 上的 NOAA Weather API

iPhone - 存储与文件相关的字符串数据的位置

json - 如何解析从 SOAP WS 的 XML 响应创建的 JSON?

java - Android:LinearLayout.addView 不渲染添加的 View

Android:多个警报不起作用

android - 我可以使用 android.preference 包执行数据库特定操作吗?