Andrew
Andrew

Reputation: 21076

MotionLayout not animating smoothly

I have a Fragment whose layout consists of a MotionLayout that has two children. One child is a horizontal RecyclerView and the other child is a FrameLayout. They are stacked vertically.

MotionLayout
--RecyclerView (horizontal)
--FrameLayout

Inside the FrameLayout is a ViewPager -- and each page is a Fragment with a vertical RecyclerView. I want the scrolling of this vertical RecyclerView to collapse/expand the FrameLayout over the horizontal RecyclerView just like a CollapsingToolbarLayout would.

It's pretty easy to get this "working" with the following scene:

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

    <Transition
        app:constraintSetEnd="@+id/collapsed"
        app:constraintSetStart="@+id/expanded">

        <OnSwipe
            app:dragDirection="dragDown"
            app:onTouchUp="autoComplete"
            app:touchAnchorId="@+id/vertical_recycler_view"
            app:touchAnchorSide="top" />

    </Transition>

    <ConstraintSet android:id="@+id/expanded">

        <Constraint
            android:id="@id/my_framelayout"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/horizontal_recycler_view" />

    </ConstraintSet>

    <ConstraintSet android:id="@+id/collapsed">

        <Constraint
            android:id="@id/my_framelayout"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </ConstraintSet>

</MotionScene>

This "works." The FrameLayout "collapses" over the horizontal RecyclerView as expected.

My issue is that the animation does not happen smoothly (over time). The FrameLayout snaps collapsed/expanded immediately.

Could anyone tell me what I'm doing wrong here?

Thanks

Upvotes: 3

Views: 1414

Answers (3)

sina akbari
sina akbari

Reputation: 736

Just change app:dragDirection="dragDown" into app:dragDirection="dragUp"

Upvotes: 0

Wai Choong Wong
Wai Choong Wong

Reputation: 69

The snaps collapsed/expanded is the intended behaviour for app:onTouchUp="autoComplete".

If you want the collapsing animation to follow your scrolling, try change the app:onTouchUp="autoComplete" to app:onTouchUp="stop".

Upvotes: 1

user3578275
user3578275

Reputation: 1

Try to change app:touchAnchorSide to bottom

Upvotes: 0

Related Questions