How to start shared element transition using Fragments?

前端 未结 8 1373
心在旅途
心在旅途 2020-12-04 06:32

I am trying to implement transitions between fragments which have \"shared elements\" as described in the new material design specs. The only method I can find is the Activi

相关标签:
8条回答
  • 2020-12-04 07:26

    This should be a comment to the accepted answer, as I am unable to comment on it.

    The accepted answer (by WindsurferOak and ar34z) works, except for a "minor" problem which caused a null pointer exception when navigating up with the backStack. It seems that setSharedElementReturnTransition() should be called on the target fragment instead of the original fragment.

    So instead of:

    setSharedElementReturnTransition(TransitionInflater.from(getActivity()).inflateTransition(R.transition.change_image_transform));
    

    it should be

    fragment.setSharedElementReturnTransition(TransitionInflater.from(getActivity()).inflateTransition(R.transition.change_image_transform));
    

    https://github.com/tevjef/Rutgers-Course-Tracker/issues/8

    0 讨论(0)
  • 2020-12-04 07:28

    The shared element fragment transitions do work with ListViews, as long as the source and target views have the same (and unique) transitionName.

    If you make your list view adapter to set unique transitionNames to the views you want (e.g. some constant + specific item id) and also change your detail fragment to set the same transitionNames to the target views at runtime (onCreateView), the transitions actually work!

    0 讨论(0)
提交回复
热议问题