0
Why Shared Element Transition with Floating Action Button is not properly aligned?

Open 0 Answers 133 Views Mobile Development
I have a RecyclerView with some cards each containing a mini Floating Action Button. When a card is clicked, the image on the card and the fab are used in a shared element transition.

When doing the return transition, the floating action button "snaps" back into its original position, rather than animating nicely as its supposed to.

Heres a gif that shows the issue: https://gfycat.com/SnappySeparateDeer

My code starting the activity and transition:

Intent intent = new Intent(mContext, PlayActivity.class);

                Pair<View, String> p1 = Pair.create((View)holder.coverArt, "coverArt");

                Pair<View, String> p2 = Pair.create((View) holder.fab, "fab");

                ActivityOptionsCompat options = ActivityOptionsCompat.

                        makeSceneTransitionAnimation(mActivity, p1, p2);

                mContext.startActivity(intent, options.toBundle());

the mini fab on the cards:

<android.support.design.widget.FloatingActionButton

            android:id="@+id/fab"

            app:fabSize="mini"

            android:layout_height="wrap_content"

            android:layout_width="wrap_content"

            app:layout_anchor="@id/coverArt"

            app:layout_anchorGravity="bottom|right|end"

            android:src="@drawable/ic_favorite"

            android:layout_margin="16dp"

            android:clickable="true"

            android:transitionName="fab"/>

and the one in the activity:

<android.support.design.widget.FloatingActionButton

        android:id="@+id/fab"

        android:layout_height="wrap_content"

        android:layout_width="wrap_content"

        app:layout_anchor="@id/coverArt"

        app:layout_anchorGravity="bottom|right|end"

        android:src="@drawable/ic_favorite"

        android:layout_margin="16dp"

        android:clickable="true"

        android:transitionName="fab"/>

EDIT: I'd like to increase the bounty but it seems that feature isnt implemented in SO for some reason. I'm pretty sure I can add additional bounty points to the correct answer, so will add another +50. Thanks!

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
...