ConstraintLayout Barrier 在设计视图中不可见

ConstraintLayout Barrier not visible in design view

我正在尝试在 Android Studio 中为我的 ConstraintLayout 添加一个障碍,但它在设计视图中没有按应有的方式显示。

我一直在关注 this tutorial,但我无法正常工作。

我目前正在使用:

我尝试过的事情:

这是我的 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>

在设计视图中,它看起来像 this

屏障卡在布局的边缘,无论我做什么都不会移动。如果我设置 barrierDirection startleft 它根本不可见。如果我设置 endright 虚线会出现,但会卡在布局的左侧。

另一个项目中的障碍 seem to work fine 是从头开始的,但这使用 android.support.constraint.ConstraintLayout 而不是 androidx 库。

这也发生在我身上。对我来说修复它的方法是关闭 Android Studio 并再次打开它。

您也可以升级到版本2.0.0-alpha3

升级到版本 2.0.0-alpha3 解决了我的问题。

我也无法显示障碍,直到我将布局名称从 app:constraint_referenced_ids 列表。然后结界出现了

当我将 constraintLayout 库从版本 2.0.4 升级到 2.1.3 时,障碍搞砸了。

我如下更改了障碍的宽度和高度,问题解决了。

之前:

<androidx.constraintlayout.widget.Barrier
    android:id="@+id/myBarrier"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:barrierDirection="end"
    app:constraint_referenced_ids="textView1,textView2,textView3"
    app:layout_constraintEnd_toEndOf="parent" />

之后:

<androidx.constraintlayout.widget.Barrier
    android:id="@+id/myBarrier"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    ...
/>