Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MotionLayout with vertical ScrollView

I'm trying to make animation with motion layout, and want to set scrollView as targetAnchor for motion scene onSwipe Transition, but it doesn't work. Maybe I don't know some thing about onSwipe transition.

Here is my layout file

    <androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/main_background_color"
        app:layoutDescription="@xml/base_scroll_scene">

        <ImageView
            android:id="@+id/background_image"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginBottom="@dimen/scrollable_background_image_margin_bottom"
            android:scaleType="centerCrop"
            android:src="@drawable/lift_bg"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/top_gradient_mask_height"
            android:background="@drawable/top_gradient_mask"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/ski_more_logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/ski_more_logo_margin_top"
            android:src="@drawable/ic_skimore_logo"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/locked_icon"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_marginTop="@dimen/locked_icon_margin_top"
            android:src="@drawable/ic_lock"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/ski_more_logo" />

        <FrameLayout
            android:id="@+id/bottom_gradient_mask"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="@drawable/bottom_gradient_mask"
            app:layout_constraintBottom_toBottomOf="@+id/background_image" />

        <ScrollView
            android:id="@+id/content_scroll_view"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:overScrollMode="never"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent">


            <FrameLayout
                android:id="@+id/content_container_view"
                android:layout_width="match_parent"
                android:clickable="false"
                android:layout_height="match_parent" />


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

In scroll view programmatically i'm adding some content with big height, which will be scrollable.

And here is my motion scene

<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:motion="http://schemas.android.com/apk/res-auto">
    <Transition
        motion:constraintSetEnd="@+id/end"
        motion:constraintSetStart="@+id/start"
        motion:duration="1000">
        <OnSwipe
            motion:dragDirection="dragUp"
            motion:touchAnchorId="@+id/content_scroll_view"
            motion:touchAnchorSide="top" />
    </Transition>

    <ConstraintSet android:id="@+id/start"/>
    <ConstraintSet android:id="@+id/end">
        <Constraint
            android:id="@+id/background_image"
            android:layout_width="0dp"
            android:layout_height="@dimen/top_gradient_mask_height"
            android:layout_marginBottom="@dimen/scrollable_background_image_margin_bottom"
            android:scaleType="centerCrop"
            android:src="@drawable/lift_bg"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintTop_toTopOf="parent" />

    </ConstraintSet>

</MotionScene>

Please help me, Thanks.

like image 417
Levon Vardanyan Avatar asked Apr 05 '19 15:04

Levon Vardanyan


2 Answers

Have you tried to replace ScrollView with NestedScrollView?

And, also, I would define ConstraintSet "start" as well.

like image 98
Nikola Avatar answered Sep 29 '22 12:09

Nikola


I had the same issue on using a scrolling view with motion layout to implement my custom animations. But simply changing ScrollView to NestedScrollView fixed everything and animations work as expected

like image 36
AliAndArdDev Avatar answered Sep 29 '22 12:09

AliAndArdDev