障碍物不动的原因

时间:2019-02-02 17:46:59

标签: android android-constraintlayout

我想使一个布局看起来像这样,但使用Barrier S: expected layout

因此,我制作了以下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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/buttonA"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="A"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/buttonB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="B"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.constraintlayout.widget.Barrier
        android:id="@+id/barrier"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="bottom"
        app:constraint_referenced_ids="buttonA,buttonB" />

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="C"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/barrier" />

</androidx.constraintlayout.widget.ConstraintLayout>

但是结果看起来像这样:

actual layout

似乎障碍物没有向下移动。我在做什么错了?

1 个答案:

答案 0 :(得分:1)

这似乎是ConstraintLayout 1.1.2中的错误。它已在1.1.3中修复,尽管1.1.3在Android Studio中显示预览可能还有其他问题。 ConstraintLayout 2.0.0-alpha3也会产生很好的预览。

相关问题