RecyclerView to ViewPager Transition

I have a RecyclerView with CardViews , and when I click on CardView , I open a new action with a ViewPager containing the data of this card.

I want to achieve :

1) When I go from the list to the Activity object, I want CardView where the common item was CardView (a bit like a Gmail application).

2) When I return from the Activity list ( ViewPager ) to the list, I need a transition in which the current element goes to its place in the list (again, as in the Gmail application).

What i have done so far :

  • I have included input and output transitions in styles.xml .

  • I declared a common element by declaring a transitionName in XML (in both files: list and viewPager).

Here are some parts of my code:

Activity Details:

 protected void onCreate (Bundle savedInstanceState) { .... viewPager = (ViewPager) findViewById(R.id.card_detail); mPagerAdapter = new DetailPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(mPagerAdapter); viewPager.setCurrentItem(currentPosition); // to go the right position in the pager... 

RecyclerView adapter (where the "Drill with Transition" operation begins):

 ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(mActivity, card, "card_transition_name"); mContext.startActivity(i, options.toBundle()); 

I left the default transition, but it’s a bit strange: the transition is a combination of gradual and zooming, which is really messy ...

Can someone help me on how to achieve this?

Thanks!

+4
source share

All Articles