【发布时间】:2019-07-03 10:40:18
【问题描述】:
我正在尝试在 Android Studio 中为我的 ConstraintLayout 添加一个障碍,但它没有在设计视图中以应有的方式显示。
我一直在关注this tutorial,但我无法正常工作。
我目前正在使用:
- Android Studio 3.1.1
androidx.constraintlayout:constraintlayout:1.1.3
我尝试过的事情:
- 使缓存无效/重新启动
- 删除属性
tools:layout_editor_absoluteX - 摆弄!
这是我的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 start 或 left 它根本不可见。如果我设置了end 或right,虚线会出现,但会卡在布局的左侧。
另一个项目中的障碍seem to work fine 是从头开始的,但这使用android.support.constraint.ConstraintLayout 而不是androidx 库。
【问题讨论】:
-
我对从 com.android.support.constraint:constraint-layout:1.1.3 创建的障碍有同样的问题
标签: android android-studio android-constraintlayout androidx