3

I'd like to create a constraint layout where I can add multiple barrier, but it doesn't work.

In the end I'd like to have a layout something like a setting page, where the elements are under each other, but when I click on some of the element, some additional element appears under it and the rest shifts down.

My approach was to use horizontal barriers and set the visibility of the additional elements, but I can't add a second barrier even in a simple example like below (the second barrier sticks to the top): example pic

Layout file:

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

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginTop="16dp"
    android:text="Button"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<android.support.constraint.Barrier
    android:id="@+id/barrier"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:barrierDirection="bottom"
    app:constraint_referenced_ids="button"
    tools:layout_editor_absoluteY="731dp" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginTop="16dp"
    android:text="Button"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="@+id/barrier" />

<android.support.constraint.Barrier
    android:id="@+id/barrier2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:barrierDirection="bottom"
    app:constraint_referenced_ids="button2"
    tools:layout_editor_absoluteY="731dp" />

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:text="Button"
    app:layout_constraintStart_toStartOf="parent"
    tools:layout_editor_absoluteY="299dp" />

</android.support.constraint.ConstraintLayout>

Any idea how to put more than one barrier in the layout or create such layout?

Razero
  • 321
  • 1
  • 4
  • 16
  • This looks OK but you might see better results if you constrain the top button and delete all the absoluteX's and absoluteY's. If that doesn't work, you can try updating to a later release of ConstraintLayout (if you can) or just try resetting the project. Sometimes just restarting Android Studio work. – Cheticamp Feb 12 '19 at 14:14
  • 1
    Turns out it actually works, only the Android studio preview is not able to show it properly... – Razero Feb 12 '19 at 21:16

0 Answers0