DeveloperKurt
DeveloperKurt

Reputation: 788

Android - Motion Layout Syntax Error: No Valid LayoutDescription

I am getting the following error when I switch to MotionLayout from ConstraintLayout. I have tried rebuilding the project but no use. Error is saying motion layout cannot be used

Error

Layout Code:

    <androidx.constraintlayout.motion.widget.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:id="@+id/fragment_death_motion_layout"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_gravity="center"
    android:layout_marginHorizontal="16dp"
    android:background="@drawable/black_gray_gradient"
    android:visibility="visible"
    app:layoutDescription="@xml/dialog_fragment_death_scene"
    tools:context=".ui.DeathDialogFragment">


    <TextView
        android:id="@+id/game_over_text_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="32dp"
        android:layout_marginEnd="16dp"
        android:text="@string/game_over"
        android:textAppearance="@style/TextAppearance.AppCompat.Display1"
        android:textColor="@android:color/white"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.496"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/score_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="24dp"
        android:text="666"
        android:textAppearance="@style/TextAppearance.AppCompat.Display3"
        android:textColor="@android:color/white"
        app:layout_constraintEnd_toEndOf="@+id/game_over_text_tv"
        app:layout_constraintStart_toStartOf="@+id/game_over_text_tv"
        app:layout_constraintTop_toBottomOf="@+id/game_over_text_tv" /
</androidx.constraintlayout.motion.widget.MotionLayout>

Upvotes: 13

Views: 5269

Answers (4)

Hayk Mkrtchyan
Hayk Mkrtchyan

Reputation: 3255

Invalidate Caches and Restart helped me

Upvotes: 1

Izzy Stannett
Izzy Stannett

Reputation: 252

Make sure the <MotionScene...> xml file is in the same module as your layout xml file

Upvotes: 0

DeveloperKurt
DeveloperKurt

Reputation: 788

I am getting this error whenever I change the constraint layout to motion layout by editing the XML manually.

However, restarting the Android Studio has solved the problem for me.

Edit: Cutting and pasting the app:layoutDescription attribute also seems to be fixing the issue if it repeates after you've got it working: app:layoutDescription="@xml/dialog_fragment_death_scene"

Upvotes: 4

hoford
hoford

Reputation: 5323

You can close the layout file's tab and reopen it.

Upvotes: 55

Related Questions