android - 无法在约束布局中添加第二个屏障
问题描述
我想创建一个约束布局,我可以在其中添加多个障碍,但它不起作用。
最后,我希望有一个类似于设置页面的布局,其中元素彼此位于下方,但是当我单击某些元素时,它下方会出现一些额外的元素,其余元素会向下移动。
我的方法是使用水平障碍并设置附加元素的可见性,但即使在下面这样的简单示例中我也无法添加第二个障碍(第二个障碍粘在顶部):
布局文件:
<?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>
知道如何在布局中放置多个障碍或创建这样的布局吗?
解决方案
推荐阅读
- wso2 - How to use private NTP service (instedad pool.ntp.org) in the syncronization of WSO2 MB cluster nodes?
- java - Docker swarm:org.apache.kafka.common.errors.TimeoutException:等待节点分配超时
- javascript - 使用 flatpickr 使用变量设置 minDate
- outlook - Win7 和 Win10 操作系统机器上 Outlook 进程的虚拟内存利用率
- python - Keras 中的排名不匹配
- java - Java ThreadPool 重用可运行对象,而不是为每个任务创建新对象
- android - Flutter 构建 apk 并安装得到 flash 空白屏幕
- azure - 将 Cosmos DB 模拟器 (MongoDB API) 迁移到 Azure 时出现致命错误
- java - 当我尝试在 Eclipse 中为 jdbc 添加外部 JAR 文件时,库选项卡中的所有键似乎都被禁用
- django - Django 中的 request.method 和 request.GET