首页 > 解决方案 > 无法为新的 MotionLayout 声明 MotionScene

问题描述

我想试试新的 MotionLayot。但我无法加载 MotionScreen。

我已将此依赖项添加到 gradle:

    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha1'
    implementation 'com.android.support:design:27.1.1'

并且能够在 xml 文件中声明运动布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.motion.MotionLayout 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"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/movingCircle"
        android:src="@drawable/ic_circle"
        android:layout_width="40dp"
        android:layout_height="40dp" />

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

但是当我试图在 xml 文件夹中添加一个新场景时,它不会弹出也不会点击到源。

<?xml version="1.0" encoding="utf-8"?>
<MotionScene //does not popup as a hint. Seems like 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:motion="http://schemas.android.com/apk/res-auto">

</MotionScene>

我做错了什么?谢谢你。

标签: androidxml

解决方案


检查您的gradle.properties文件并删除此行

android.useAndroidX=true
android.enableJetifier=true

因为constraint-layout:2.0.0仅适用于经典支持包


推荐阅读