Как исправить ненужное пространство в макете ограничения? - PullRequest
0 голосов
/ 04 июня 2018

У меня есть Constraint Layout.Цель состоит в том, чтобы сложить два recyclerview друг на друга.Причина, по которой я использую Constraint Layout, заключается в том, что я также хочу, чтобы TextView занимал то же пространство, что и нижний recyclerview.(Я программно установлю TextView, чтобы он был виден, когда у нижнего recyclerview нет содержимого).

Вот макет:

<?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="250dp"
    android:background="@color/heart_red"
    tools:context=".MainActivity">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/tabRecyclerView"
        android:layout_width="0dp"
        android:layout_height="50dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toTopOf="@id/imageRecyclerView"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/imageRecyclerView"
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:background="@color/lightshade"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="@id/tabRecyclerView" />


</android.support.constraint.ConstraintLayout>

Также вот макет длястолбец элемента в моем imageRecyclerView:

<?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"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@color/darkshade">

    <ImageView
        android:id="@+id/itemImage"
        android:adjustViewBounds="true"
        android:scaleType="fitStart"
        android:layout_width="wrap_content"
        android:layout_height="150dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@id/itemFavoriteButton"/>

    <me.zhanghai.android.materialprogressbar.MaterialProgressBar
        android:id="@+id/itemProgressBar"
        android:indeterminate="true"
        android:layout_width="wrap_content"
        android:layout_height="150dp"
        app:layout_constraintLeft_toRightOf="parent"
        app:layout_constraintRight_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@id/itemFavoriteButton"/>

    <ToggleButton
        android:id="@+id/itemFavoriteButton"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@drawable/ic_favorite"
        android:textOff=""
        android:textOn=""
        android:text=""
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/itemImage"
        app:layout_constraintBottom_toBottomOf="parent"/>


</android.support.constraint.ConstraintLayout>

Однако по какой-то причине в нижней части Constraint Layout есть красная полоса, например:

Screenshot Of Phone

Насколько я могу судить, математически все проверяется.Так почему же красная полоса внизу моего макета?

1 Ответ

0 голосов
/ 05 июня 2018

Вы пытаетесь расположить виды переработчика поверх друг друга, верно?

В настоящее время вы не можете суммировать высоты tabRecyclerView и imageRecyclerView, поскольку они перекрывают друг друга.

Проверьте это

  • Высота родительского макета 250dp

  • tabRecyclerView 50dp

  • imageRecyclerView имеет 200dp (но из-за этой строки app:layout_constraintTop_toTopOf="@id/tabRecyclerView", его перекрывающаяся tabRecyclerView)
  • Отсутствует 50dp (именно поэтому красный фон от родителя отображается)

Исправить

изменить

app:layout_constraintTop_toTopOf="@id/tabRecyclerView"

на

app:layout_constraintTop_toBottomOf="@id/tabRecyclerView"

...