9

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!

Floern
  • 33,559
  • 24
  • 104
  • 119
Elye
  • 53,639
  • 54
  • 212
  • 474

2 Answers2

4

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();
            }
        });
Thorben
  • 1,019
  • 7
  • 20
0

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

Defuera
  • 5,356
  • 3
  • 32
  • 38