Android Studio找不到MotionLayout的类

5

我正在尝试使用安卓的MotionLayout,但是它找不到相应的类并且无法正常工作。

我尝试了以下依赖项:

implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta1'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta1'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha2'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha4'

但是它们似乎都没有用...

以下是我的XML文件:

<android.support.constraint.motion.MotionLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
footstools="http://schemas.android.com/tools"
android:id="@+id/motionLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:showPaths="true"
tools:context=".PlayGameActivity">

<View
    android:id="@+id/button"
    android:layout_width="64dp"
    android:layout_height="64dp"
    android:background="@color/colorAccent"
    android:text="Button" />

</android.support.constraint.motion.MotionLayout >'

但是它总是给我显示这个错误消息:
Missing classes
The following classes could not be found:
- android.support.constraint.motion.MotionLayout (Fix Build Path, Edit XML, Create Class)
Tip: Try to build the project.   
Tip: Try to refresh the layout.

在项目的预览窗口中,它会用灰色填充整个布局,并在中心写入以下内容:
android...MotionLayout
1个回答

4

android.support.constraint.motion.MotionLayout已不再使用。

implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta2"中,应使用androidx.constraintlayout.motion.widget.MotionLayout替代它。

如果MotionLayout呈灰色,则可能缺少app:layoutDescription XML文件。

AndroidX和Support Library版本有一个示例可供参考。


谢谢您的回答,但问题仍然存在(我还尝试了您提供的链接中的所有方法),不幸的是,对我来说似乎没有任何作用。 - Lidor Eliyahu Shelef

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