Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why MotionLayout collapsing animation not auto completed with NestedScrollView?

I have created custom collapsing view using MotionLayout instead of Coordinator everything is working except auto completion of animation or in coordinator we can call it snapping, like when we scroll and stop scroll in between then Collapsing view will auto snap either top or bottom. but this is not happening if i use NestedScrollView inside MotionLayout. I have created sample to demo this. I have also added app:onTouchUp="autoComplete" but it does not work.

motion_layout.xml

<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"
app:layoutDescription="@xml/motion_scene">

<View
    android:id="@+id/collapsible"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/red" />

<androidx.core.widget.NestedScrollView
    android:id="@+id/nested_scroll_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <View
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:background="#EEE" />

    ///.......///

    </LinearLayout>

</androidx.core.widget.NestedScrollView>

motion_scene.xml

<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <Transition
        app:constraintSetEnd="@id/end"
        app:constraintSetStart="@id/start"
        app:duration="1000">

        <OnSwipe
            app:dragDirection="dragUp"
            app:onTouchUp="autoComplete"
            app:touchAnchorId="@id/nested_scroll_view"
            app:touchAnchorSide="top" />

    </Transition>

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

        <Constraint
            android:id="@+id/collapsible"
            android:layout_width="0dp"
            android:layout_height="300dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Constraint
            android:id="@id/nested_scroll_view"
            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/collapsible" />

    </ConstraintSet>

    <ConstraintSet
        android:id="@+id/end"
        app:deriveConstraintsFrom="@id/start">

        <Constraint
            android:id="@+id/collapsible"
            android:layout_width="0dp"
            android:layout_height="100dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Constraint
            android:id="@id/nested_scroll_view"
            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/collapsible" />

    </ConstraintSet>

</MotionScene>
like image 479
Kulwinder Singh Rahal Avatar asked Jun 06 '26 19:06

Kulwinder Singh Rahal


1 Answers

Just Add to The NestedScrollView > LinearLayout

android:descendantFocusability="blocksDescendants"
like image 61
Mohhamed Nabil Avatar answered Jun 08 '26 08:06

Mohhamed Nabil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!