即使我使用 layout_margin 也无法防止视图重叠

Can't keep views from overlapping even when I use layout_margin

我不知道如何正确呈现我的列表项。一切似乎都很好,直到文本标题太长。查看下面的图片,我将标题固定在 listItem 视图的左侧和 imageView 的右侧。我什至尝试将右侧锚定到整个视图的右边缘,但没有成功。如果用户输入的标题太长,视图就会重叠。 我希望标题在 imageview 和整个 listItem 视图的左侧之间居中。我提供了这一切如何呈现的图片。任何帮助将不胜感激。当标题足够长时,它会包裹住很好的文本。在这一点上,我什至会接受尾随......但我更愿意让文字换行。我只是不想重叠图像视图。我还发布了 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="wrap_content"
    android:orientation="vertical"
    android:padding="5dp"
    android:id="@+id/list_item_container">

    <TextView
        android:id="@+id/match_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:textSize="16sp"
        tools:text="Match Name"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="16dp"
        app:layout_constraintRight_toLeftOf="@+id/imageView"
        android:layout_marginRight="8dp"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"/>

    <TextView
        android:id="@+id/match_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:text="Match Date"
        android:textAlignment="center"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        app:layout_constraintRight_toLeftOf="@+id/imageView"
        android:layout_marginRight="8dp"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/match_name"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginBottom="8dp"/>


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="60dp"
        android:layout_height="45dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:layout_marginEnd="8dp"
        android:layout_weight="1"
        app:srcCompat="@drawable/ic_more_vert_black_24dp"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="8dp"
        android:layout_marginRight="68dp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginBottom="8dp"
        app:layout_constraintVertical_bias="0.484"/>

    <TextView
        android:id="@+id/match_id_hidden"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        android:visibility="invisible"
        tools:layout_editor_absoluteY="67dp"
        tools:layout_editor_absoluteX="24dp"/>


</android.support.constraint.ConstraintLayout>

为您的两个 TextView 设置 android:layout_width="0dp"。在 ConstraintLayout 中,值“0dp”基本上意味着匹配约束。 "wrap_content" 的值在测量视图时不考虑约束,仅在定位视图时考虑。

ConstraintLayout 中尝试始终使用“0dp”作为您的高度和宽度,并始终为所有视图的所有 4 个边设置 app:layout_constraint..._to...Of。检查结果,然后微调以获得预期的结果。在 XML 而不是在可视化编辑器中执行此操作;根据我的经验,它更快并且避免了 layout_editor_absolute... 设置。