android lollipop-setentertransition()用于片段在退出时无法正常工作 [英] android lollipop - setentertransition() for fragment not working properly on exiting

本文介绍了android lollipop-setentertransition()用于片段在退出时无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在替换片段时,我正在使用可用于android棒棒糖版本的Slide动画.对于此特定替换,它可以正常工作,但是在按下后退"按钮时,它首先会弹出当前片段&然后执行输入动画的反向操作(滑出).

While replacing fragment, I am using Slide animation available for android lollipop version. It works as expected for this particular replacement, but on pressing back button it first pops back current fragment & then reverse of enter animation (slide out) is executed.

private void replaceContentFrameByFragment(Fragment replaceBy, String replaceByFragmentTag) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Slide slide = new Slide(Gravity.BOTTOM);
            slide.setDuration(1000);
            replaceBy.setEnterTransition(slide);
    }
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.content_frame, replaceBy, replaceByFragmentTag);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commitAllowingStateLoss();
}

那么,如何迫使片段仅在幻灯片的反向动画完成后才弹出?我注意到活动提供了方法finishAfterTransition().会有类似的东西吗?

So, how to force fragment to pop back only after reverse animation of slide is finished? I noticed that activity has method finishAfterTransition() provided. Is there something similar for frgament?

推荐答案

我遇到了同样的问题,片段B的onReturn-> A,片段B似乎在进行额外的幻灯片过渡.为了解决这个问题,我在淡入淡出过渡setReturnTransition()中的时间比看上去很不错的幻灯片要短(因为它溶解到先前的片段中).的代码是:

I had the same issue, onReturn from Fragment B -> A, Fragment B seem to be doing an extra slide transition. To get around it, I put in a fade transition for setReturnTransition() of a shorter time than the slide which looks quite good (as it dissolves into previous fragment). The code for this is:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Slide slideRight = new Slide(Gravity.RIGHT);
    slideRight.setDuration(200);
    fragment.setEnterTransition(slideRight);
    Fade fade = new Fade();
    fade.setDuration(100);
    fragment.setReturnTransition(fade);
}

这篇关于android lollipop-setentertransition()用于片段在退出时无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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