问题
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:
- Android Studio 3.1.1
androidx.constraintlayout:constraintlayout:1.1.3
Things I have tried:
- Invalidate caches/restart
- Removing the attribute
tools:layout_editor_absoluteX
- Fiddling around!
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.
回答1:
Upgrading to version 2.0.0-alpha3
solved the issue for me.
回答2:
It just happened to me as well. What fixed it for me was simply closing Android Studio and open it up again.
You can also upgrade to version 2.0.0-alpha3
来源:https://stackoverflow.com/questions/54605100/constraintlayout-barrier-not-visible-in-design-view