android / views-widgets-samples

Multiple samples showing the best practices in views-widgets on Android.
Apache License 2.0
5.05k stars 3.01k forks source link

MotionLayout is not working well as a child of a NestedScrollView #50

Open maozgal opened 5 years ago

maozgal commented 5 years ago

I have a RecyclerView inside MotionLayout, and the MotionLayout is a child of NestedScrollView

https://gist.github.com/maozgal/8edc8d1ac9e215279a21b262b9a00449

The NestedScrollView blocks the dragging events from getting to my RecyclerView. When I'm changing MotionLayout to ConstraintLayout everything works well.

Wrakor commented 5 years ago

I'm having the exact same issue. Have you found any solution? Currently using constraint layout 2.0 alpha 4

abhimuktheeswarar commented 5 years ago

Not working well - can be more specific? For me, it is laggy, shuttering

Wojtek1234 commented 5 years ago

I have created something like this

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

<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/motionLayout" android:layout_width="match_parent" android:layout_height="match_parent" app:layoutDescription="@xml/scene_26"

<ImageView
        android:id="@+id/arrow_right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_keyboard_arrow_right"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        />

<ImageView
        android:id="@+id/arrow_up"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="316dp"
        android:src="@drawable/ic_keyboard_arrow_up"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.552"
        app:layout_constraintStart_toStartOf="parent"
        />

<View
        android:id="@+id/dial_pad"
        android:layout_width="match_parent"
        android:layout_height="500dp"
        android:background="@color/cerulean_blue"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="parent"
        />

<androidx.core.widget.NestedScrollView
        android:background="@color/brown"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:id="@+id/linearLayout"
        app:layout_constraintTop_toBottomOf="@id/dial_pad"
        >
    <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/motionInside"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >

            <Button

                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@color/azure"
                    android:text="1"
                    android:layout_gravity="top"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    android:id="@+id/b1"
                    />

            <Button
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@color/azure"
                    android:text="2"
                    android:layout_gravity="top"
                    android:id="@+id/b2"
                    android:layout_marginTop="300dp"
                    app:layout_constraintTop_toBottomOf="@+id/b1"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    />

            <Button
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@color/azure"
                    android:text="3"
                    android:layout_gravity="top"
                    android:id="@+id/b3"
                    android:layout_marginTop="300dp"
                    app:layout_constraintTop_toBottomOf="@+id/b2"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    />

            <Button
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@color/azure"
                    android:text="4"
                    android:layout_gravity="top"
                    android:id="@+id/b4"
                    android:layout_marginTop="300dp"
                    app:layout_constraintTop_toBottomOf="@+id/b3"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    />

            <Button
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@color/azure"
                    android:text="5"
                    android:layout_gravity="top"
                    android:id="@+id/b5"
                    android:layout_marginTop="300dp"
                    app:layout_constraintTop_toBottomOf="@+id/b4"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    />

            <Button
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@color/azure"
                    android:text="6"
                    android:layout_gravity="top"
                    android:id="@+id/b6"
                    android:layout_marginTop="300dp"
                    app:layout_constraintTop_toBottomOf="@+id/b5"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    />

            <Button
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@color/azure"
                    android:text="7"
                    android:layout_gravity="top"
                    android:id="@+id/b7"
                    android:layout_marginTop="300dp"
                    app:layout_constraintTop_toBottomOf="@+id/b6"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    />

            <Button
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@color/azure"
                    android:text="8"
                    android:layout_gravity="top"
                    android:id="@+id/b8"
                    android:layout_marginTop="300dp"
                    app:layout_constraintTop_toBottomOf="@+id/b7"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    />

            <Button
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@color/azure"
                    android:text="9"
                    android:layout_gravity="top"
                    android:id="@+id/b9"
                    android:layout_marginTop="300dp"
                    app:layout_constraintTop_toBottomOf="@+id/b8"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    />

            <Button
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@color/azure"
                    android:text="10"
                    android:layout_gravity="top"
                    android:id="@+id/b10"
                    android:layout_marginTop="300dp"
                    app:layout_constraintTop_toBottomOf="@+id/b9"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    />
    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.core.widget.NestedScrollView>

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

with scene animation like ` <MotionScene xmlns:android="http://schemas.android.com/apk/res/android" xmlns:motion="http://schemas.android.com/apk/res-auto">

<Transition
        motion:constraintSetEnd="@id/dial"
        motion:constraintSetStart="@id/base_state"
        motion:duration="3000">
    <OnSwipe
            motion:dragDirection="dragUp"
            motion:touchAnchorId="@id/dial_pad"
            motion:touchAnchorSide="top" />
</Transition>

<ConstraintSet android:id="@+id/base_state">
    <Constraint android:id="@id/dial_pad">
        <Layout
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginTop="-16dp"
                motion:layout_constraintEnd_toEndOf="parent"
                motion:layout_constraintStart_toStartOf="parent"
                motion:layout_constraintTop_toBottomOf="parent" />
    </Constraint>

    <Constraint android:id="@id/linearLayout">
        <Layout
                android:layout_marginTop="-16dp"
                android:layout_width="match_parent"
                android:layout_height="2000dp"
                android:orientation="vertical"
                motion:layout_constraintTop_toBottomOf="@id/dial_pad" />
    </Constraint>

</ConstraintSet>

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

    <Constraint android:id="@id/dial_pad">
        <Layout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginTop="120dp"
                motion:layout_constraintBottom_toBottomOf="parent"
                motion:layout_constraintEnd_toEndOf="parent"
                motion:layout_constraintStart_toStartOf="parent" />
    </Constraint>

    <Constraint android:id="@id/linearLayout">
        <Layout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:layout_marginTop="120dp"
                motion:layout_constraintBottom_toBottomOf="parent"  />
    </Constraint>

</ConstraintSet>

`

In such situation in end position nested scroll view does not scroll. If you change motionInside layout to ConstrainLayout it works as excepted

Obehi commented 4 years ago

Is there any progress or known solutions on this issue?

mohhamednabil commented 4 years ago

Just Add android:descendantFocusability="blocksDescendants" To the LinearLayout inside NestedScrollView

andor201995 commented 4 years ago

I tried Static data (long string in resource file ) in Motion Layout's ScrollVIew then it work's fine but if i use dynamic data inside the ScrollView (same length string then) Scrolling stop's working

Related SOF Question i posted:

https://stackoverflow.com/questions/60242215/how-to-let-nestedscrollview-scroll-in-motionlayout

ucingHitam commented 3 years ago

Just Add android:descendantFocusability="blocksDescendants" To the LinearLayout inside NestedScrollView

wow here !! if nested scrol to below view in motionlayout.

thanks work for me