Elye
Elye

Reputation: 60081

Shared Element Transition into a View in a RecyclerView, possible?

In view of normal Lollipop transition of Activity having shared elements, e.g. https://github.com/codepath/android_guides/wiki/Shared-Element-Activity-Transition, it is quite common one is transitioning from a View from a Recycler View into a normal View of a targeted Activity.

However, in the event of the targeted view, is also in a viewholder of a recyclerView, is there a way to make that possible (i.e. provide the targeted view to the ActivityOptionsCompat)?

Thanks!

Upvotes: 9

Views: 2082

Answers (2)

Thorben
Thorben

Reputation: 1029

It is absolutely possible. Do do that you have to follow these steps:

  1. Postpone the transition in your target activity with supportPostponeEnterTransition().
  2. Set the adapter to the RecyclerView.
  3. Start the postponed transition after the RecyclerView has drawn the items.

Step 3 usually works with this:

recyclerview.post(new Runnable() {
            @Override
            public void run() {
                supportStartPostponedEnterTransition();
            }
        });

Upvotes: 4

Defuera
Defuera

Reputation: 5506

According to my investigation this is not possible. Before a shared element transition can create its animation, it must first capture each shared element’s start and end state—namely its position, size, and appearance in both the calling and called Activities/Fragments. With this information, the transition can determine how each shared element view should animate into place. (via http://www.androiddesignpatterns.com/2015/01/activity-fragment-shared-element-transitions-in-depth-part3a.html)

Official documentation declares limitations:

Classes that extend AdapterView, such as ListView, manage their child views in ways that are incompatible with the transitions framework. If you try to animate a view based on AdapterView, the device display may hang.

http://developer.android.com/training/transitions/overview.html#Limitations

Upvotes: 0

Related Questions