Material Design parent-child navigational transition recyclerview entry to detail fragment

和自甴很熟 提交于 2019-12-08 04:46:36

问题


Background

I am trying to implement the "parent-to-child" navigational transition specifically when you click a Recyclerview entry and the details appear in a fullscreen fragment. Something like this:

Question

How do I go about doing this with so many animation APIs available? (TransitionManager.beginDelayedTransition, SharedTransition, setExitTransition, etc)

What I have tried

  • InboxRecyclerView - This matches my requirements EXCEPT that it seems to only work when the detail view is in the same layout as the Recyclerview. Because I am navigating between fragments using the fragment backstack, I need it to transition between layouts that might not be available prior to attachment.

  • This post - Answers only cover activity-to-activity transitions. I am looking for fragment-to-fragment.

  • Custom Transition - I tried extending the Transition class, but I ran into the problems. CaptureStartValues() seems to capture values from the entire scene. I need it to only capture values from the recyclerview entry. Also, for some reason, the end values are not captured seeing as I get null endValues in the function createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues).

    TransitionSet exitTransition = new TransitionSet()
            .addTransition(new ChangeBounds())
            .addTransition(new ChangeTransform())
            .addTransition(new ChangeClipBounds())
            .addTransition(new ChangeImageTransform())
            .addTransition(new Expand())
            .setOrdering(TransitionSet.ORDERING_TOGETHER);
    TransitionSet enterTransition = new TransitionSet()
            .addTransition(new Fade());
    newFragment.setEnterTransition(enterTransition);
    oldFragment.setExitTransition(exitTransition);
    

回答1:


You should use shared element transitions here. There will be 2 shared elements: your RecyclerView's item background and TextView (for example). Your RecyclerView's item background should be stretched (you need to use ChangeTransform and ChangeBounds transitions) to your SecondFragment's background, and your TextView should be moved to SecondFragment's title. And you should use animations for your Shared Element transitions: firstly you should elevate item background of your RecyclerView, then you start stretching the background and moving your title, and in the end you should set your elevation back to normal. And note that all this time your first fragment should be visible, so you should set an exit duration to it: fragment1.setExitTransition(new Fade().setDuration(1).setStartDelay(<duration_of_transition>));.

So the main goal here is to use SharedElement transitions. There is a very good article aboud SharedElement fragment to fragment transitions.



来源:https://stackoverflow.com/questions/53016732/material-design-parent-child-navigational-transition-recyclerview-entry-to-detai

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