没有找到类“androidx.constraintlayout.ConstraintLayout”

Tla*_*-ES 2 android android-layout androidx

我正在为 Android 开发一个库,这个库有一些关于它的布局的活动。

在布局中,我有下一个代码

...
  <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.floatingactionbutton.FloatingActionButton
...
Run Code Online (Sandbox Code Playgroud)

我正在使用 Androidx。

我收到以下错误:

错误膨胀类 android.support.constraint.ConstraintLayout

解决此问题的第一次尝试是更改android.support.constraint.ConstraintLayoutandroidx.constraintlayout.widget.ConstraintLayout

但是当我这样做时,我收到以下错误:

androidx.constraintlayout.widget.ConstraintLayout 不能转换为 androidx.constraintlayout.widget.Group

所以我试着改成 androidx.constraintlayout.widget.Group

我收到以下错误:

androidx.constraintlayout.widget.Group 无法转换为 android.view.ViewGroup

我再次对androidx进行了重构,然后出现以下错误:

没有找到类“androidx.constraintlayout.ConstraintLayout”

任何的想法?

谢谢

Nil*_*hod 5

按照以下步骤操作

首先dependencies在您的Build.Gradle文件中添加以下内容

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
Run Code Online (Sandbox Code Playgroud)

ConstraintLayout像这样使用这个

<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="wrap_content">

</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

ConstraintLayout如果您使用过,请确保您的活动中有正确的导入

import androidx.constraintlayout.widget.ConstraintLayout
Run Code Online (Sandbox Code Playgroud)