Fragment shared element transitions don't work with ViewPager

后端 未结 3 1800
无人及你
无人及你 2020-12-12 20:40

My app contains a view which consists of a ViewPager consisting of a handful of fragments. When you click on an item in one of these fragments, the expected behavior is for

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 21:15

    I have been banging my head against the wall with this one recently. All I wanted was a Fragment in a ViewPager to launch another Fragment with a nice expanding card type shared element transition. None of the suggestions above worked for me so I decided to try launching an Activity styled like a Dialog:

    
    

    Then to launch the Activity from the Fragment:

    Intent intent = new Intent(getContext(), MyDialogActivity.class);
    ActivityOptionsCompat options = ActivityOptionsCompat
                            .makeSceneTransitionAnimation(getActivity(),
                                    Pair.create(sharedView, "target_transition"));
    ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
    

    In the Fragment layout put an android:transition_name on the sharedView and in the Activity layout have android:transition_name="target_transition" (same as Pair.create() second argument).

提交回复
热议问题