Android - 调用活动完成的共享元素转换() [英] Android - Shared element transitions with calling activity finish()

查看:520
本文介绍了Android - 调用活动完成的共享元素转换()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使应用程序更具实质性,而我只是坚持如何实现一些共享元素转换。我有一个活动A,它启动另一个B然后调用finish()以便从后栈中删除它。在我的情况下,我有一个我想在两个活动之间分享的元素,但是一旦它从A传递到B,A就不再重要了。
如果我在startActivity(ctx,intent,bundle)之后没有调用finish(),则退出/输入动画效果很好。但是,如果我打电话给完成,那么在动画开始之前就会出现一个非常丑陋的闪烁。

I'm working on making an application more Material and I'm just stuck on how to implement some shared element transitions. I have an activity A that starts another B and then calls finish() in order to remove it from the back stack. In my case I have an element I want to share between the two activities, but once it is passed from A to B, A no longer matters. If I don't call finish() after startActivity(ctx,intent, bundle) the exit/enter animation works perfectly. However, if I do call finish, there's a really ugly flicker before the animation starts.

我有什么东西可以忽略或是不可能做到我我试图做什么?

Is there something I'm overlooking or is it just not possible to do what I am trying to do?

推荐答案

如果您只希望在转换时发生这种情况,您可以在onStop函数中完成您的活动从A到B然后创建一个标志并在调用startActivity(ctx,intent,bundle)后设置它:

You can finish your activity in the onStop function, if you only want this to happen when you transition from A to B then create a flag and set it after you call startActivity(ctx,intent, bundle):

@Override
public void onStop() {
    super.onStop();
    if(mShouldFinish)
         finish();
}

确保完成活动B后调用finish()而不是finishAfterTranstion(),因为活动A不再存在

Make sure when you are done with activity B to call finish() and not finishAfterTranstion() since activity A is no longer there

完成活动A后,如果按回,B中的共享元素可能会挂起。在 ActivityB.onEnterAnimationComplete 中将transitionName设置为null以避免这种情况。

After finishing the activity A, shared element in B might hang in screen if you press back. Set transitionName to null in ActivityB.onEnterAnimationComplete to avoid this.

这篇关于Android - 调用活动完成的共享元素转换()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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