重新打开堆栈中的现有活动时的共享元素过渡 [英] Shared Element Transition when reopening existing Activity in stack Reorder To Front

查看:55
本文介绍了重新打开堆栈中的现有活动时的共享元素过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从那里有一个活动A,我打开了活动B,并将共享元素传递给它.它可以动画化过渡效果,但是当我返回到活动A,然后再次使用

I have an Activity A from there I open Activity B, and pass the shared element to it. It animates the transition fine, but when I go back to Activity A and then go to Activity B again which is still in the stack using

intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

共享元素转换未运行.

对于常规动画,您可以在onNewIntent中调用overridePendingTransition()来运行动画. https://stackoverflow.com/a/8327091

With regular animations you call overridePendingTransition() in onNewIntent for the animations to run. https://stackoverflow.com/a/8327091

我尝试在那里调用startPostponedEnterTransition(),但是什么也没发生.

I tried calling startPostponedEnterTransition() in there but nothing happened.

这是我的代码,允许进行转换

This is my code to allow for transitions

void allowWindowTransitions(){
Window w = getWindow();
w.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);  

启动活动的代码

intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    ActivityOptionsCompat options = ActivityOptionsCompat.
            makeSceneTransitionAnimation(this, sharedElement, "profile");

startActivity(intent, options.toBundle());

我试图弄乱setSharedElementReturnTransition&setSharedElementReenterTransition,但什么也没发生.

I have tried messing around with setSharedElementReturnTransition & setSharedElementReenterTransition but nothing happened.

有没有一种方法可以手动触发共享元素转换来解决此问题.

Is there a way trigger shared element transition manually to get around this.

推荐答案

不确定共享元素的转换,但是您可以覆盖onNewIntent方法在活动进入前台时应用动画.

Not sure about Shared element transitions but you can override onNewIntent method to apply animations when activity comes in foreground.

@OverrideonNewIntent(Intent intent){super.onNewIntent(intent);Log.i(TAG,"onNewIntent:");overridePendingTransition(R.anim.transition_enter_from_right,R.anim.transition_exit_to_left);} 希望这会有所帮助!

这篇关于重新打开堆栈中的现有活动时的共享元素过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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