Android enter/exit和popEnter/popExit动画之间有什么区别?
在Android enter/exit和popEnter/popExit动画之间有什么区别?,android,fragmenttransaction,fragment-backstack,Android,Fragmenttransaction,Fragment Backstack,在setCustomAnimations()中,动画需要四个资源id。我不太理解他们。如果有人对此有更清楚的了解,如果您能解释一下,我们将不胜感激 假设在占位符和backback中有一个add片段 FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.holder, fragA, FragmentA.FRAGMENT_NAME); ft.addToBackStack(FragmentA.FR
setCustomAnimations()
中,动画需要四个资源id。我不太理解他们。如果有人对此有更清楚的了解,如果您能解释一下,我们将不胜感激
假设在占位符和backback中有一个add片段
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.holder, fragA, FragmentA.FRAGMENT_NAME);
ft.addToBackStack(FragmentA.FRAGMENT_NAME);
ft.setCustomAnimations(R.anim.slide_in_from_bottom, R.anim.slide_in_from_top, R.anim.slide_in_from_left, R.anim.slide_in_from_right);
ft.show(frag);
ft.commit();
并用片段B替换:
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.holder, fragB, FragmentB.FRAGMENT_NAME);
ft.addToBackStack(FragmentB.FRAGMENT_NAME);
ft.setCustomAnimations(R.anim.slide_in_from_bottom, R.anim.slide_in_from_top, R.anim.slide_in_from_left, R.anim.slide_in_from_right);
ft.show(frag);
ft.commit();
下一次如果执行popstack()
它将从哪个事务的动画运行
/**
* Set specific animation resources to run for the fragments that are
* entering and exiting in this transaction. The <code>popEnter</code>
* and <code>popExit</code> animations will be played for enter/exit
* operations specifically when popping the back stack.
*/
public abstract FragmentTransaction setCustomAnimations(@AnimRes int enter,
@AnimRes int exit, @AnimRes int popEnter, @AnimRes int popExit);
让我们从简单的案例开始: 将片段A替换为片段B(第二个代码片段)
- 片段B进入动画
- 片段A运行退出动画
- 片段B运行popExit动画
- 片段A运行PopCenter动画
- 片段B运行popExit动画(在第二个片段中设置)
- 片段0运行PopCenter动画(在第一个片段中设置)
- 片段B运行popExit动画(在第二个片段中设置)
- 由于容器现在为空,因此不运行PopCenter动画
/**
* Set specific animation resources to run for the fragments that are
* entering and exiting in this transaction. The <code>popEnter</code>
* and <code>popExit</code> animations will be played for enter/exit
* operations specifically when popping the back stack.
*/
public abstract FragmentTransaction setCustomAnimations(@AnimRes int enter,
@AnimRes int exit, @AnimRes int popEnter, @AnimRes int popExit);