androidx.constraintlayout.widget.ConstraintLayout没有可以拖动的链。

23

我在我的布局中使用了androidx.constraintlayout.widget.ConstraintLayout,但是它没有显示链条,而且我也无法拖动任何小部件。我只是输入我想要使用的约束条件。

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="112dp"/>

这是一个androidx ConstraintLayout 的示例截图: androidx.constraintlayout.widget.ConstraintLayout

但是当我尝试切换回android.support.constraint.ConstraintLayout时,我看不到它。

<android.support.constraint.ConstraintLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="112dp"/>

这是支持约束布局的示例截图: android.support.constraint.ConstraintLayout

这是一个bug还是其他什么问题吗?

编辑:

目前我的解决方案是从以下方式进行切换:

implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'

但是这并不能解决我的问题,因为我不想使用支持。

2个回答

38

在意识到应该使用Canary版本解决问题之前,我遇到了同样的问题。在安装了稳定版本旁边的Canary版本后,打开项目,现在你可以使用这个实现:

implementation 'androidx.constraintlayout:constraintlayout:1.1.2'

而不是

implementation 'com.android.support.constraint:constraint-layout:1.1.2'

请记住您可能需要执行以下操作:

  • 清理项目
  • 重新构建
  • 无效缓存/重启

使用这种方法解决了我的问题。


1
我在使用金丝雀版本时遇到了这个问题。我意识到可能是因为在“金丝雀”版本中我们会遇到更多的错误,而且错误可以自动修复。我将我的Android Studio更新到了3.3金丝雀6版本,现在它可以正常工作了。 - raquezha
1
清理项目就是我所要做的。 - bickster

14

如果您正在使用最新的Android更新3.3.3,则应从支持约束布局迁移到Android x:

<android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>

<androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

为了实现这个,还需要更改gradle文件:

implementation com.android.support.constraint:constraint-layout:1.1.3

更改为

implementation androidx.constraintlayout:constraintlayout:2.0.0-alpha3


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接