title: RecyclerView shared element transition - return to different position
body: <p>In my app I have a RecyclerView that looks like this:
  <a href="https://i.stack.imgur.com/rKbHT.png" rel="nofollow noreferrer">screenshot</a></p>
  
  <p>Each item represents one message; unread messages always appear on the top of the list. If you click on any item, whole fragment is being replaced by a corresponding DetailsFragment. I have set up a shared element transition from list item background to details fragment background to make "expand" effect. It works beautifully when selected message is already read; however, if you open an unread message, it gets marked as read and thus, changes position in the list. If you then try to return to the fragment with RecyclerView, no shared element transition is played: details fragment disappears with the default transition(fade). 
  I searched the docs, but shared element transitions aren't really documented well. Does anyone know any solution or workaround for this issue?</p>
  
  <p>edit: I set up the transition in onClick of the RecyclerView as follows:</p>
  
  <pre><code>@Override
          public void onItemClick(View view, int position) {
                  FragmentManager fragmentManager = getFragmentManager();
                  FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                  MessageDetailsFragment fragment = MessageDetailsFragment.newInstance(message);
                  RelativeLayout background = (RelativeLayout) view.findViewById(R.id.three_line_list_item_background);
  
                  TransitionInflater transitionInflater = TransitionInflater.from(getContext());
                  Transition t = new Fade();
                  Transition details_enter = transitionInflater.inflateTransition(R.transition.details_enter);
                  Transition details_exit = transitionInflater.inflateTransition(R.transition.details_exit);
  
                  fragment.setSharedElementEnterTransition(details_enter);
                  fragment.setSharedElementReturnTransition(details_exit);
                  setSharedElementEnterTransition(details_enter);
                  setSharedElementReturnTransition(details_exit);
  
                  fragment.setExitTransition(t);
                  fragment.setEnterTransition(t);
                  fragment.setReturnTransition(t);
                  fragment.setReenterTransition(t);
  
                  setEnterTransition(t);
                  setExitTransition(t);
                  setReturnTransition(t);
                  setReenterTransition(t);
  
                  fragmentTransaction.addSharedElement(background, background.getTransitionName());
                  fragmentTransaction.addToBackStack(null).commit();
                  fragmentTransaction.replace(((ViewGroup) getView().getParent()).getId(), fragment);
          }
  </code></pre>
  
  <p>Transition names(composed of unique message IDs) are set programatically in RecyclerView adapter's onBindViewHolder() and DetailFragment's onCreateView()</p>