How to start shared element transition using Fragments?

前端 未结 8 1407
心在旅途
心在旅途 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

提交回复
热议问题