如何动画片段去除 [英] How to animate fragment removal

查看:139
本文介绍了如何动画片段去除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要动画拆除片段。

我想:

getSupportFragmentManager().beginTransaction()
    .setCustomAnimations(R.anim.push_down_in, R.anim.push_up_out)
    .remove(myFragment)
    .commit();

但片段就这样消失。

but the fragment just disappears.

我注意到了动画只播放与'取代',所以我试图用一个空的片段像这样的替换片段:

I noticed the out animation only plays with 'replace', so I tried to replace the fragment with an empty Fragment like this:

getSupportFragmentManager()
    .beginTransaction()
    .setCustomAnimations(R.anim.push_down_in, R.anim.push_up_out)
    .replace(viewId, new Fragment())
.commit();

但它仍然只是消失消失。

But it still just disappears disappears.

所以,我怎么能动画切除片段?

So, how can I animate the removal of fragment?

推荐答案

我想它了。

排出的视图是动画的进入视图的画布上,以便如果不存在进入印刷品没有印刷品为动画。

The exiting view is animated on the canvas of the entering view so if there is no entering canvas there is no canvas for the animation.

要显示动画我不得不总是使用替换,并使用相同尺寸的碎片进入到那些正在退出。动画后完成我设置了新片段的视图来了。

To show the animation I had to always use replace and use entering fragments of the same size to those exiting. After the animation is finished I set the view of the new fragments to gone.

这篇关于如何动画片段去除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆