启动活动与动画 [英] Start Activity with an animation

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

问题描述

我想开始一个自定义的过渡动画的活动。我发现了迄今为止唯一的办法做到这一点(没有在previous活动使用onPendingTransition())是使用自定义主题的活动,并确定任何activityOpenEnterAnimation,taskOpenEnterAnimation,windowEnterAnimation或windowAnimationStyle设置动画。但是,所有这些属性都为我工作。有些实验得出以下结果 -

I am trying to start an activity with a custom transition animation. The only way I have found out so far to do this (without using onPendingTransition() in the previous activity) is to use a custom theme on the activity and define either activityOpenEnterAnimation, taskOpenEnterAnimation, windowEnterAnimation or windowAnimationStyle to set the animation. But, none of these attributes are working for me. Some experimentation yielded the following results-

如果我设置了windowAnimationStyle属性的一些定义为activityOpenEnterAnimation,taskOpenEnterAnimation,windowEnterAnimation或windowAnimationStyle值我可以摆脱在活动开始出现默认的过渡动画的自定义样式。使用指定的实际值,但至少有默认的动画未示出它不显示的过渡的动画。

If I set the windowAnimationStyle attribute to some custom style which defines values for activityOpenEnterAnimation, taskOpenEnterAnimation, windowEnterAnimation or windowAnimationStyle I can get rid of the default transition animation occurring at the start of the activity. It doesn't show the transition animation using the actual value specified but at least the default animation is not shown.

据这里参考文档

According to the reference doc here,

我应该能够在使用activityOpenEnterAnimation该活动的开始到定义的动画。但没有成功为止。

I should be able to define an animation at the start of the activity using activityOpenEnterAnimation. But no success so far.

任何想法?

推荐答案

我在我的当前项目使用此,它基本上是pretty的简单。您在styles.xml定义一个新的动画风格,像这样的:

I am using this in a current project of mine, it is basically pretty simple. You define a new animation style in your styles.xml, like this:

<!-- just defines top layer "Animation" -->
<style name="Animation" />

<!-- the animations must have been defined in your "anim" folder, of course -->
<style name="Animation.MyAwesomeAnimation" parent="android:style/Animation.Activity">
    <item name="android:activityOpenEnterAnimation">@anim/myawesomeanimation_enter</item>
    <item name="android:activityOpenExitAnimation">@anim/hold_long</item>
    <item name="android:activityCloseEnterAnimation">@anim/hold_long</item>
    <item name="android:activityCloseExitAnimation">@anim/myawesomeanimation_exit</item>
</style>

然后设置这种风格的一个主题(的themes.xml):

Then set this style in a theme (themes.xml):

<style name="Theme.MyAwesomeTheme" parent="Theme.Default">
    <item name="android:windowAnimationStyle">@style/Animation.MyAwesomeAnimation</item>
</style>

然后你可以设置这些主题为每一个你想在你的Andr​​oidManifest.xml活动:

And then you can simply set these themes to every activity you like in your AndroidManifest.xml:

<activity
    android:name=".MyAwesomeActivity"
    android:theme="@style/Theme.MyAwesomeTheme" />

现在我希望你大乐趣活动的动画! - D

Now I wish you big fun with activity animations! :-D

这篇关于启动活动与动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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