Android ListView 布局未展开

Android ListView layout not expaind

我有一个带有自定义适配器的简单 ListView。我已经使用 ConstraintLayout 对项目布局进行了建模。一切正常,除非某个 TextView 包含长文本,使其位于第二行并与下一个文本重叠。如何让项目只在需要时垂直展开?

我的列表视图:

<?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="org.altervista.realms.biomap.fragments.EditFragment">

    <ListView
        android:id="@+id/recordsListView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:divider="@drawable/list_divider"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

我的适配器布局:

<?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="wrap_content"
    android:background="@drawable/record_row"
    android:longClickable="true"
    >


    <Button
        android:id="@+id/editRecordDeleteButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="8dp"
        android:background="@drawable/button"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:minHeight="40dp"
        android:minWidth="40dp"
        android:text="@string/icon_delete"
        android:textAppearance="@style/TextAppearance.AppCompat.Medium"
    />

    <TextView
        android:id="@+id/editRecordDate"
        android:text="21/06/2015"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="4dp"
    />

    <TextView
        android:id="@+id/editRecordSpecies"
        android:text="Russola Magnificens Russola Magnificens"
        android:textColor="#000000"
        android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/editRecordDate"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/editRecordAbundance"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="4dp"
    />

    <TextView
        android:id="@+id/editRecordLocHab"
        android:text="Faggeta acidofila a Luzula Croce di Forcella Piccola"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginLeft="8dp"
        android:layout_marginBottom="4dp"
        app:layout_constraintRight_toLeftOf="@+id/editRecordDeleteButton"
        android:layout_marginRight="8dp"
        android:layout_marginTop="4dp"
        app:layout_constraintTop_toBottomOf="@+id/editRecordSpecies"
    />

    <TextView
        android:id="@+id/editRecordTime"
        android:text="14:44"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/editRecordDeleteButton"
        android:layout_marginRight="8dp"
        android:layout_marginTop="4dp"
    />

    <TextView
        android:id="@+id/editRecordAbundance"
        android:text="2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/editRecordTime"
        app:layout_constraintRight_toLeftOf="@+id/editRecordDeleteButton"
        android:layout_marginRight="8dp"
        android:layout_marginTop="4dp"
        android:layout_marginBottom="4dp"
    />

</android.support.constraint.ConstraintLayout>

现在的样子:

我想要垂直展开的第 3 项(并且只有第 3 项)。 谢谢!

编辑:

我注意到只有当文本比行稍长时才会出现此问题。使用较长的文本会导致 TextView 按预期扩展。

在我看来,它使用父级宽度来决定何时扩展布局,而它使用 textview 宽度来决定何时换行。

请注意,下面图片的 XML 是相同的。我只更改了文本字符串。

从您那里删除 app:layout_constraintBottom_toBottomOf="parent" 属性 editRecordLocHab textView 解决了我复制代码中的问题。