Search code examples
androidandroid-layoutandroid-motionlayout

Only first transition works in multistate transitions motionlayout


I am testing multistate transitions just like in the below sample.

https://github.com/googlearchive/android-ConstraintLayoutExamples/blob/multi_state/motionlayout/src/main/res/xml/scene_26.xml

My layout is pretty straightfoward. It has a header with a recyclerview below it. So for testing purposes I am trying to perform the following transitions.

Transition 1 Header changes its size from 500dp(start state) to 200dp(intermediate state)

Transition 2 Header changes its size from 200dp(intermediate state) to 0dp(end state)

The problem is only first transition happens. My desired behavior is when I scroll the list T1 occurs and right after it T2 should occur making the header collapse completely.

Please NOTE- I am doing this for testing only. I have an animation that I need to develop that uses the same principle here

Here's the code

Layout

<?xml version="1.0" encoding="utf-8"?>

<layout 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">

    <androidx.constraintlayout.motion.widget.MotionLayout
        android:id="@+id/motion_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:showPaths="true"
        app:layoutDescription="@xml/scrollable_header_above_recycler_view_scene">

        <ImageView
            android:id="@+id/header"
            android:layout_width="0dp"
            android:layout_height="500dp"
            android:background="@color/colorPrimary"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:paddingTopSystemWindowInsets="@{true}"
            tools:ignore="ContentDescription" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/list"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:clipToPadding="false"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/header"
            app:paddingBottomSystemWindowInsets="@{true}" />

    </androidx.constraintlayout.motion.widget.MotionLayout>
</layout> 

MotionLayout

<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:motion="http://schemas.android.com/apk/res-auto">

    <Transition
        motion:constraintSetStart="@+id/start"
        motion:constraintSetEnd="@+id/intermediate"
      >
        <OnSwipe
            motion:onTouchUp="stop"
            motion:dragDirection="dragUp"
            motion:touchAnchorSide="bottom"
            motion:touchAnchorId="@+id/header" />
    </Transition>

    <Transition
        motion:constraintSetStart="@+id/intermediate"
        motion:constraintSetEnd="@+id/end"
        >
        <OnSwipe
            motion:onTouchUp="stop"
            motion:dragDirection="dragDown"
            motion:touchAnchorSide="bottom"
            motion:touchAnchorId="@+id/header" />
    </Transition>





    <ConstraintSet android:id="@+id/start">
        <Constraint
            android:id="@+id/header"
            android:layout_width="match_parent"
            android:layout_height="500dp"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintTop_toTopOf="parent" />


    </ConstraintSet>


    <ConstraintSet android:id="@+id/intermediate">
        <Constraint
            android:id="@+id/header"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"
            />
    </ConstraintSet>


    <ConstraintSet android:id="@+id/end">
        <Constraint
            android:id="@+id/header"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"
            />
    </ConstraintSet>


</MotionScene> 

Solution

  • MotionLayout does not support Multi-state transitions of NestedScrollView/RecyclerView. It would generate way to many corner cases.