Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

android - Fragment shared element transition with add() instead of replace()?

I am trying to make a shared element transition between fragments, everything works fine when using replace() to add the second fragment, however in the codebase add() is used a lot, but when using that, transition just skips to end values

Is it possible to have the transition between added fragments? Thanks

@Override
public void onClick(View v) {
    setSharedElementReturnTransition(TransitionInflater.from(getActivity())
        .inflateTransition(android.R.transition.move));

    FragmentB secondFragment = new FragmentB();
    secondFragment.setSharedElementEnterTransition(TransitionInflater.from(getActivity())
        .inflateTransition(android.R.transition.move));

    getFragmentManager().beginTransaction()
        .add(R.id.container, secondFragment)
        .addToBackStack(null)
        .addSharedElement(imageView, imageView.getTransitionName())
        .commit();
}
question from:https://stackoverflow.com/questions/29259829/fragment-shared-element-transition-with-add-instead-of-replace

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

since the system isnt going through the onPause from the first fragment its not going to happen. becuase when you add a new fragment, the new fragment comes on the top of the old fragment.

but you can fake it though you will have more code !

there is a sample below:

https://github.com/Kisty/FragmentTransitionExample

and a video not compeletely related but helps you to get the idea:

https://www.youtube.com/watch?v=CPxkoe2MraA


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...