imageView вызывает сокращение родительского макета в макете ограничений - PullRequest
0 голосов
/ 20 ноября 2018

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

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

<TextView
    android:id="@+id/crime_title"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:background="@color/cardview_light_background"
    android:text="Crime Title"
    android:textColor="@android:color/black"
    android:textSize="18sp"
    app:layout_constraintBottom_toTopOf="@+id/crime_date"
    app:layout_constraintEnd_toStartOf="@+id/crime_solved"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/crime_date"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginTop="4dp"
    android:layout_marginBottom="8dp"
    android:padding="2dp"
    android:text="Crime Date"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/crime_title" />

<ImageView
    android:id="@+id/crime_solved"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="0dp"
    android:layout_marginTop="8dp"
    android:layout_marginBottom="7dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/ic_solved"
    tools:adjustViewBounds="true" />


</android.support.constraint.ConstraintLayout>

! [Скриншот проблемы] https://imgur.com/gallery/UwrCdsq

1 Ответ

0 голосов
/ 21 ноября 2018

установите ImageView высоту и ширину на 0dp и установите следующие свойства, как показано ниже

app:layout_constraintWidth_default="wrap"
app:layout_constraintHeight_default="wrap"

также удалите ненужные margins из вашего TextView

...