Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared element transition with viewPager

Tags:

android

I have problem with sharedElementTransitions. I have one activity with fragment - from this fragment I start new activity with sharedElementTransitions, inside this activity I start fragment and inside this fragment is viewPager, now when I call setTransitionName in this fragment everything works very well, but when I move it to fragment that is inside my viewPager and call it inside onCreateView there is no smooth enter animation, back animation is working as intended. I was quite sure this might be resolved using postponeEnterTransition, so in my activity with fragment with viewPager I am calling postponeEnterTransition() and in my fragment getActivity().startPostponedEnterTransition() but it is still not working... Any ideas what might go wrong?

like image 590
user3274539 Avatar asked Apr 21 '15 14:04

user3274539


1 Answers

// Postpone the shared element enter transition in onCreate()
postponeEnterTransition();

// after the layout and data is ready, invoke startPostponedEnterTransition() to start the enter transition animation
// for example: 
sharedElement.getViewTreeObserver().addOnPreDrawListener(
 new ViewTreeObserver.OnPreDrawListener() {
     @Override
     public boolean onPreDraw() {
         sharedElement.getViewTreeObserver().removeOnPreDrawListener(this);
         startPostponedEnterTransition();
         return true;
     }
});

Please refer to : http://www.androiddesignpatterns.com/2015/03/activity-postponed-shared-element-transitions-part3b.html for more details

Hope it will be helpful!

like image 90
Dan Meng Avatar answered Oct 18 '22 14:10

Dan Meng