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

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

问题描述

我想动画删除片段.

我试过了:

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

但是片段就消失了.

我注意到 out 动画只播放替换",所以我尝试用这样的空片段替换片段:

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天全站免登陆