Having issues using Android 5.0 Activity transitions onto an activity with a ViewPager

倖福魔咒の 提交于 2019-12-03 10:04:24

Building off George Mount's answer, you could try adding the following code in your called Activity's onCreate() method:

postponeEnterTransition(); 
viewPager.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { 
    public boolean onPreDraw() { 
        viewPager.getViewTreeObserver().removeOnPreDrawListener(this);
        startPostponedEnterTransition();
        return true;
    }
});

Here are a few ideas:

You can delay the transition until the ViewPager activity is ready using Activity.postponeEnterTransition() in the ViewPager activity. When it is ready to start the transition, run Activity.startPostponedEnterTransition().

If you want the transition to happen quicker and the images are similar (not cropped differently), you can use the shared element snapshot and scale it. You can see an example of using the snapshot here: https://halfthought.wordpress.com/2014/12/10/reveal-challenge/

If the image in your calling Activity is cropped, but you have an uncropped image backing it (e.g. ImageView crops the image), you can override the onCaptureSharedElementSnapshot in the calling Activity to return the uncropped bitmap in the calling Activity. Then in your ViewPager Activity, you can use the onCreateSharedElementSnapshot to pick up that image for your transition.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!