ViewPager Fragments – Shared Element Transitions

前端 未结 2 1530
醉酒成梦
醉酒成梦 2020-12-07 14:47

An app I\'m developing displays a grid of images. When you tap an image, it goes into the details view. The details view contains a ViewPager that allows you swipe between e

2条回答
  •  萌比男神i
    2020-12-07 15:35

    I'm assuming that you're using Fragment Transitions and that you're not animating between Activities. It is possible in both Activity Transitions and Fragment Transitions, but the specific code is a little different. The postpone is not available on Fragment Transitions, though.

    The addSharedElement takes a second parameter. If you know the specific name in the target fragment when you call it, you can just choose the name in the details fragment to use. If you don't, you can choose any name you want and remap it with the SharedElementCallback set on the Fragment.

    fragment.setEnterSharedElementCallback(new SharedElementCallback() {
        @Override
        public void onMapSharedElements(List names, Map sharedElements) {
            sharedElements.put("detailView", mTargetDetailView);
        }
    });
    

    If it doesn't match on the way back, the same call is made to remap it. This is likely going to be both in the calling fragment and the called fragment -- on the calling fragment, you use setExitSharedElementCallback. I expect this is the case in your app.

    Likewise, in Activity Transitions, you set the same SharedElementCallback and use the same mapping, but you do it on the Activity instead.

提交回复
热议问题