0

I have a Barrier which references three views. These three views are beneath one another, like this:

---- View A

---- View B

---- Group 

--------- Barrier

---- View D

View D has a constraint to the Barrier and View B and the Group at any time may become become View.GONE.

Furthermore, the Group is initially empty. I programmatically inflate views under View B and I associate all of them to the Group.

The Problem though is that when I inflate views in to the Group, View D does not move and stays underneath View B.

Code which shows the Group, the Barrier and View D:

<androidx.constraintlayout.widget.Group
    android:id="@+id/group"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toBottomOf="@id/view_b" />

<androidx.constraintlayout.widget.Barrier
    android:id="@+id/header_barrier"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:barrierDirection="bottom"
    app:constraint_referenced_ids="group, view_a, view_b" />

<View
    android:id="@+id/bottom_shadow"
    android:layout_width="0dp"
    android:layout_height="@dimen/grid_8"
    android:background="@drawable/orders_shadow_white"
    app:layout_constraintBottom_toBottomOf="@id/barrier"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />
Subby
  • 5,370
  • 15
  • 70
  • 125

1 Answers1

1

You have made mistake in bottom_shadow View's constarint.

It should be layout_constraintTop_toBottomOf instead of layout_constraintBottom_toBottomOf.

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp">

    <View
        android:id="@+id/view_a"
        android:layout_width="0dp"
        android:layout_height="20dp"
        android:background="@android:color/holo_blue_dark"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <View
        android:id="@+id/view_b"
        android:layout_width="0dp"
        android:layout_height="20dp"
        android:background="@android:color/holo_green_dark"
        app:layout_constraintStart_toStartOf="@+id/view_a"
        app:layout_constraintTop_toBottomOf="@+id/view_a" />

    <androidx.constraintlayout.widget.Group
        android:id="@+id/group"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:constraint_referenced_ids="view_b"
        app:layout_constraintTop_toBottomOf="@id/view_b" />

    <androidx.constraintlayout.widget.Barrier
        android:id="@+id/header_barrier"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="bottom"
        app:constraint_referenced_ids="group, view_a, view_b" />

    <View
        android:id="@+id/bottom_shadow"
        android:layout_width="0dp"
        android:layout_height="20dp"
        android:background="@android:color/holo_orange_light"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/header_barrier" />

</androidx.constraintlayout.widget.ConstraintLayout>
Shweta Chauhan
  • 6,739
  • 6
  • 37
  • 57