6

My case is I'm having only 1 activity. Firstly, it displays fragment1, inside that fragment, i have a recyclerView to display a list of cardviews, inside each CardView, there is an image. When user tap on each CardView, fragment1 will be replaced by the fragment 2. Fragment2 contains a viewPager, viewpager display the same data with recyclerView in fragment1 but more specific. I want to make a shareElement animation between image1 in fragment1 to image2 in fragment2. enter image description here What I did is: OnLickListener of recyclerView, I set transitionName for image1 by item's code

    image1.setTransitionName(item.getContentID().toString());

Replace framgent and addShareElement:

  fragmentTransaction
                .replace(R.id.fragment, sharedElementFragment2, FragmentEnum.FEED.toString())
                .addToBackStack(null)
                .addSharedElement(image1,image1.getTransitionName())
                .commit();

In fragment of viewPager, I update image2 with transitionName was sent by fragment 1

@Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        view.findViewById(R.id.image2).setTransitionName(feed.getContentID()+"");

    }

But it doesn't work. I tried to put image2 outside viewpager (directly under fragment 2 ) and it works. It seems that shareElement doesn't work when the target element inside viewPager. Any solution for this?

phuchieu
  • 114
  • 7
  • what tutorials you have followed so far ? – Rahul Khurana Oct 16 '16 at 15:42
  • I followed this tut: http://www.androidauthority.com/using-shared-element-transitions-activities-fragments-631996/ But in their example, the target fragment doesn't contain viewpager – phuchieu Oct 17 '16 at 01:05
  • Possible duplicate of [ViewPager Fragments – Shared Element Transitions](https://stackoverflow.com/questions/27304834/viewpager-fragments-shared-element-transitions) – M. Reza Nasirloo Jul 11 '17 at 18:19

1 Answers1

0

This post aims to provide guidelines and implementation for a specific continuous transition between Android Fragments. We will demonstrate how to implement a transition from an image in a RecyclerView into an image in a ViewPager and back, using 'Shared Elements' to determine which views participate in the transition and how.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Piyu
  • 43
  • 2
  • 8