I'm trying to add a barrier to my ConstraintLayout
in Android Studio but it is not showing up the way it should in design view.
I have been following this tutorial, but I can't get things to work properly.
I'm currently using:
androidx.constraintlayout:constraintlayout:1.1.3
Things I have tried:
tools:layout_editor_absoluteX
Here's my test.xml
:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button" android:layout_marginTop="8dp"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"/>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/button" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"/>
<androidx.constraintlayout.widget.Barrier android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/barrier2" app:barrierDirection="end"
app:constraint_referenced_ids="button,button2"
tools:layout_editor_absoluteX="411dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
In design view, it looks like this
The barrier is stuck to the edge of the layout and doesn't move no matter what I do. If I set barrierDirection
start
or left
it is not visible at all. If I set end
or right
the dashed line shows up but is stuck to the left side of the layout.
Barriers seem to work fine in another project started from scratch, but this uses the android.support.constraint.ConstraintLayout
rather than the androidx
library's.
Upgrading to version 2.0.0-alpha3
solved the issue for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With