【问题标题】:ConstraintLayout Barrier not visible in design viewConstraintLayout Barrier 在设计视图中不可见
【发布时间】: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 startleft 它根本不可见。如果我设置了endright,虚线会出现,但会卡在布局的左侧。

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

【问题讨论】:

  • 我对从 com.android.support.constraint:constraint-layout:1.1.3 创建的障碍有同样的问题

标签: android android-studio android-constraintlayout androidx


【解决方案1】:

升级到版本 2.0.0-alpha3 为我解决了这个问题。

【讨论】:

  • 在 2.0.0-alpha3 上测试过。有趣的是,2.0.0-beta3 的设计视图已损坏
  • 确认,2.0.0-beta3 > 2.0.0-alpha3,但错误在2.0.0-beta3
【解决方案2】:

这也发生在我身上。解决这个问题的方法是关闭 Android Studio 并再次打开它。

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

【讨论】:

    【解决方案3】:

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

    【讨论】:

      【解决方案4】:

      当我将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"
          ...
      />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-27
        • 1970-01-01
        相关资源
        最近更新 更多