ConstraintLayout屏障在设计视图中不可见 [英] ConstraintLayout Barrier not visible in design view

查看:101
本文介绍了ConstraintLayout屏障在设计视图中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Android Studio中为我的 ConstraintLayout 添加障碍,但是并没有在设计视图中显示出应有的方式.

I'm trying to add a barrier to my ConstraintLayout in Android Studio but it is not showing up the way it should in design view.

我一直在关注本教程,但是我无法正常工作.

I have been following this tutorial, but I can't get things to work properly.

我当前正在使用:

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

在设计视图中,它看起来像

In design view, it looks like this

障碍物固定在布局的边缘,无论我做什么都不会动.如果我将 barrierDirection 设置为 start left ,则根本看不到.如果我设置 end right ,则虚线会出现,但会停留在布局的左侧.

The barrier is stuck to the edge of the layout and doesn't move no matter what I do. If I set barrierDirection start or left it is not visible at all. If I set end or right the dashed line shows up but is stuck to the left side of the layout.

在另一个从头开始的项目中,似乎正常工作的障碍,但这使用了 android.support.constraint.ConstraintLayout 而不是 androidx 库的

Barriers seem to work fine in another project started from scratch, but this uses the android.support.constraint.ConstraintLayout rather than the androidx library's.

推荐答案

升级到版本 2.0.0-alpha3 为我解决了此问题.

Upgrading to version 2.0.0-alpha3 solved the issue for me.

这篇关于ConstraintLayout屏障在设计视图中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆