动画删除片段
问题描述:
在一个应用程序中,我尝试对删除片段进行动画处理。动画删除片段
transaction.remove(fragmentVideo).remove(fragmentProgressBar).replace(R.id.content_pane_calling, endFragment);
transaction.setCustomAnimations(R.anim.slide_in, R.anim.slide_up);
transaction.commit();
该框架完全忽略了这一点。片段本身被删除,但视觉不好。任何FragmentTransaction#replace
适用于这些动画。我使用的是SupportLibrary v23.1.
谢谢你帮我出:)
答
这是我曾经遇到一个很常见的问题。在决定使用Fragments时我非常小心,因为它们对于UI动画非常不灵活。你可能会在这里找到答案:
http://daniel-codes.blogspot.com/2013/09/smoothing-performance-on-fragment.html
你也可以动画的片段和你用动画完成后,在适当的顺序分别做两件事执行拆除交易。
//Pseudo Code
Animation anim = ... //this animates your fragment view
anim.setAnimationListener(new AnimationListener() {
void onAnimFinish() {
transaction.remove(fragmentVideo).remove(fragmentProgressBar).replace(R.id.content_pane_calling, endFragment);
transaction.setCustomAnimations(R.anim.slide_in, R.anim.slide_up);
transaction.commit()
getFragmentManager().executePendingTransactions();
}
})
答
到transaction.setCustomAnimation()的调用,必须调用之前transaction.remove()/加()/替换()或动画将永远不会被运行。
所以您的代码将是这样的:
transaction.setCustomAnimations(R.anim.slide_in, R.anim.slide_up);
transaction.remove(fragmentVideo).remove(fragmentProgressBar).replace(R.id.content_pane_calling, endFragment);
transaction.commit();
我测试了这个已经,它不是为我工作 – Kitesurfer
啊确定。看起来这个问题已经在http://stackoverflow.com/questions/13982240/how-to-animate-fragment-removal之前被询问过,并且当动画在传入视图上运行时,您实际上无法动画化删除片段。我所链接的问题有一些如何解决这个问题的想法。 – BadMouse