【问题标题】:androidx.constraintlayout.widget.constraintlayout don't have chains that you can dragandroidx.constraintlayout.widget.constraintlayout 没有可以拖动的链
【发布时间】:2018-12-11 07:32:01
【问题描述】:

我在我的布局中使用 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

这是一个错误还是什么?

编辑:

我目前的解决方案是从:

implementation 'androidx.constraintlayout:constraintlayout:1.1.2'

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

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

【问题讨论】:

    标签: android android-constraintlayout constraint-layout-chains androidx


    【解决方案1】:

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

    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
    

    而不是

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

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

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

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

    【讨论】:

    • 当我遇到这个时,我正在使用金丝雀版本。我意识到这可能是因为它在“金丝雀”版本中我们遇到了更多错误,并且错误可以自动修复。我将我的 Android Studio 更新到 3.3 Canary 6,现在它可以工作了
    • 我只需要清理项目
    【解决方案2】:

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

    <android.support.constraint.ConstraintLayout>
    </android.support.constraint.ConstraintLayout>
    
    <androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    为了得到这个也改变gradle:

    实现 com.android.support.constraint:constraint-layout:1.1.3

    实现androidx.constraintlayout:constraintlayout:2.0.0-alpha3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-08
      • 2012-01-24
      • 2015-03-16
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 2016-04-07
      相关资源
      最近更新 更多