Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Can';t在约束布局中添加第二个屏障_Android_Layout_Android Constraintlayout_Barrier - Fatal编程技术网

Android Can';t在约束布局中添加第二个屏障

Android Can';t在约束布局中添加第二个屏障,android,layout,android-constraintlayout,barrier,Android,Layout,Android Constraintlayout,Barrier,我想创建一个约束布局,在这里我可以添加多个屏障,但它不起作用 最后,我希望有一个类似于设置页面的布局,其中元素位于彼此下方,但当我单击某些元素时,一些额外的元素出现在其下方,其余元素向下移动 我的方法是使用水平屏障并设置附加元素的可见性,但即使在下面这样的简单示例中,我也无法添加第二个屏障(第二个屏障粘贴在顶部): 布局文件: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.Constrai

我想创建一个约束布局,在这里我可以添加多个屏障,但它不起作用

最后,我希望有一个类似于设置页面的布局,其中元素位于彼此下方,但当我单击某些元素时,一些额外的元素出现在其下方,其余元素向下移动

我的方法是使用水平屏障并设置附加元素的可见性,但即使在下面这样的简单示例中,我也无法添加第二个屏障(第二个屏障粘贴在顶部):

布局文件:

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


您知道如何在布局中放置多个屏障或创建这样的布局吗?

这看起来不错,但如果您约束顶部按钮并删除所有absoluteX和absoluteY,您可能会看到更好的结果。如果这不起作用,您可以尝试更新到ConstraintLayout的更高版本(如果可以的话),或者只是尝试重置项目。有时只是重新启动Android Studio工作。事实证明它确实工作,只有Android Studio预览无法正确显示它。。。