活动退出动画无法在Android 4.0上正常运行 [英] Activity exit animations don't work as expected on Android 4.0

查看:133
本文介绍了活动退出动画无法在Android 4.0上正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个更改活动的打开/关闭/进入/退出动画的主题:

I have a theme that changes the activity's open/close/enter/exit animations:

<style name="down_up_theme" parent="Theme.rtlfr">
    <item name="android:windowAnimationStyle">@style/down_up_animation</item>
</style>

<style name="down_up_animation" parent="@android:style/Animation.Activity">
    <item name="android:activityOpenEnterAnimation">@anim/slide_in_top</item>
    <item name="android:activityOpenExitAnimation">@anim/hold</item>
    <item name="android:activityCloseEnterAnimation">@anim/hold</item>
    <item name="android:activityCloseExitAnimation">@anim/slide_out_bottom</item>
</style>

在清单中:

<activity android:name=".activity.ArticlesActivity"
        android:theme="@style/down_up_theme" />

目标是使活动内容在开始时向下滑动,并在退出时向上滑动。

The goal is to make the activity content slide down on start, and slide up at exit.

动画在2.3上运行良好。但是在4.0上,退出动画(向上滑动)不起作用。它所做的动画是关闭从该活动产生的活动。就我而言,我想用文章列表为活动的结束设置动画,而不是文章详细信息的结尾具有向上滑动的动画。

The animations work fine on 2.3. On 4.0, though, the exit animation (slide up) doesn't work. What it does animate is the closing of the activities that are spawned from this activity. In my case, I want to animate the closing of the activity with the list of articles, instead the closing of the article detail has the slide up animation.

我想我可以尝试将结束动画添加到生成我要设置动画的活动的活动中,但实际上生成应该具有不同动画的活动。在文档中,我也找不到关于2.3与4.0差异的任何信息。 。

I guess I could try to add the closing animation to the activity that spawns the one I want to animate, but it actually spawns activities that should have different animations. I also couldn't find any information on this 2.3 vs. 4.0 difference in the documentation.

如何使动画在4.0上正常播放?

How can I make my animations work on 4.0?

推荐答案

我不确定为什么在主题中设置的退出动画在ICS +上不起作用,但是调用 overridePendingTransition()似乎有效。为您执行此操作的最简单方法可能是在您的活动中覆盖 finish()

I'm not sure why the exit animation set in the theme is not working on ICS+, but calling overridePendingTransition() seems to be working. The simplest way to do this for you is probably to override finish() in your Activity:

@Override
public void finish() {
    super.finish();
    overridePendingTransition(R.anim.hold, R.anim.slide_out_bottom);
}

这篇关于活动退出动画无法在Android 4.0上正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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