问题描述
在Android的棒棒糖,在 活动#postponeEnterTransition()
和 活动#startPostponedEnterTransition()
方法给出的活动推迟开始进入和退出共享单元的转换,直到所有数据被加载的能力。这些为活动
过渡工作的伟大。
In Android Lollipop, the Activity#postponeEnterTransition()
and Activity#startPostponedEnterTransition()
methods give the Activity the ability to delay starting the entering and exiting shared element transitions until all data is loaded. These work great for Activity
transitions.
有没有办法使用片段
转换时,达到同样的效果?
Is there a way to achieve the same effect when using Fragment
transitions?
推荐答案
有没有直接等效片段转换,因为片段使用FragmentTransaction,我们真的不能推迟东西是应该发生在一个事务中。
There's no direct equivalent in Fragment Transitions because Fragments use FragmentTransaction and we can't really postpone something that is supposed to happen in a transaction.
要获得相当的,你可以添加一个片段,并把它藏在一个事务中,那么当片段准备就绪后,删除旧的片段,并显示在一个事务中的新片段。
To get the equivalent, you can add a Fragment and hide it in a transaction, then when the Fragment is ready, remove the old Fragment and show the new Fragment in a transaction.
getFragmentManager().beginTransaction()
.add(R.id.container, fragment2)
.hide(fragment2)
.commit();
后来,当fragment2准备就绪:
Later, when fragment2 is ready:
getFragmentManager().beginTransaction()
.addSharedElement(sharedElement, "name")
.remove(fragment1)
.show(fragment2)
.commit();
这篇关于如何推迟片段的进入Android的棒棒糖过渡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!