davideas / FlexibleAdapter

Fast and versatile Adapter for RecyclerView which regroups several features into one library to considerably improve the user experience :-)
Apache License 2.0
3.55k stars 548 forks source link

StickyHeaders dissappear in a motion layout #703

Open Stevemoretz opened 5 years ago

Stevemoretz commented 5 years ago

When I use a recyclerview in a motionlayout and swipe it up I see the the recyclerView and eveything works perfectly the only problem is stickyHeaders don't work if after the motionlayout,Is swiped up I swipe it down a little and then use recyclerview it works.But can I do anything in the code so I get this fixed?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:id="@+id/root">

    <androidx.constraintlayout.motion.widget.MotionLayout
        android:id="@+id/motionLayout"
        app:layoutDescription="@xml/scene3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:showPaths="true">
        <ImageView
            android:id="@+id/image"
            android:src="@drawable/ic_launcher_background"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <RelativeLayout
            android:id="@+id/testId"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toBottomOf="parent"
            app:layout_constraintVertical_chainStyle="spread">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recycler_media_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="10dp"/>

            <com.google.android.material.floatingactionbutton.FloatingActionButton
                android:id="@+id/media_send_fab"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentBottom="true"
                android:layout_margin="16dp"
                android:onClick="sendTheMessages"
                app:fabSize="normal" />
        </RelativeLayout>
    </androidx.constraintlayout.motion.widget.MotionLayout>
</RelativeLayout>

and scene3.xml

<?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:constraintSetEnd="@+id/end"
        motion:constraintSetStart="@+id/start"
        motion:duration="300"
        motion:interpolator="linear">
        <OnSwipe
            motion:touchAnchorId="@+id/image"
            motion:touchAnchorSide="top"
            motion:dragDirection="dragUp" />
    </Transition>
    <ConstraintSet android:id="@+id/start">
        <Constraint
            android:id="@+id/testId"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintTop_toBottomOf="parent"
            motion:layout_constraintVertical_chainStyle="spread">
        </Constraint>
        <Constraint
            android:id="@+id/image"
            motion:layout_constraintBottom_toBottomOf="parent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />

    </ConstraintSet>
    <ConstraintSet android:id="@+id/end">
        <Constraint
            android:id="@+id/testId"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintTop_toTopOf="parent"
            motion:layout_constraintVertical_chainStyle="spread">
        </Constraint>
        <Constraint
            android:id="@+id/image"
            motion:layout_constraintBottom_toTopOf="parent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
    </ConstraintSet>
</MotionScene>
davideas commented 5 years ago

@Stevemoretz, thank for the message, actually the sticky header wasn't tested with this layout. It looks unsupported then, but I can't say anything more until I try. Sincerely, I can't now.

Stevemoretz commented 5 years ago

Ok man thanks for the reply.Give it a try and let us know!motion layouts are brilliant!

TreyWurm commented 5 years ago

Facing the same problem using the ATM newest library androidx.constraintlayout:constraintlayout:2.0.0-alpha4
Its sufficient to just replace any parent layout with MotionLayout. Even without any specific MotionLayout events like swiping this behavior occurs.

Played around a little bit, and it seems like the properties of the added FrameLayout containing the sticky header does not get measured. I can see it in the LayoutInspector but with measuredWidth/height == 0

evgenybozhko2 commented 1 year ago

Confirmed! Not working with the motion layout. Any animation does not work. Still no solution?