Android: Activities animations not working

2019-04-27 06:10发布

问题:

I have not been able to understand why my custom animations are not overriding the system animations when i switch between activities in my app.

styles.xml

<style name="AppBaseTheme" parent="android:Theme.Holo.Light"></style>

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:buttonStyle">@style/buttonStyle</item>
    <item name="android:actionBarStyle">@style/ActionBarStyle</item>
    <item name="android:editTextStyle">@style/editTextStyle</item>
    <item name="android:windowAnimationStyle">@style/ActivityAnimationStyle</item>
</style>

<!-- activities animation style start -->
<style name="ActivityAnimationStyle" parent="@android:style/Animation.Activity">
    <item name="android:activityOpenEnterAnimation">@anim/fadein</item>
    <item name="android:activityOpenExitAnimation">@anim/fadeout</item>
    <item name="android:activityCloseEnterAnimation">@anim/fadein</item>
    <item name="android:activityCloseExitAnimation">@anim/fadeout</item>
</style>
<!-- activities animation style end -->

fadein.xml:

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="@android:integer/config_longAnimTime"
    android:fromAlpha="0.0"
    android:interpolator="@android:anim/anticipate_interpolator"
    android:toAlpha="1.0" />

fadeout.xml

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="@android:integer/config_longAnimTime"
    android:fromAlpha="1.0"
    android:interpolator="@android:anim/anticipate_interpolator"
    android:toAlpha="0.0" />

Manifest:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

With these all set, I was hoping to see fading animations but this is not happening at all.

FYI, I noticed if I use android:windowEnterAnimation and android:windowExitAnimation instead and increase value of android:duration to something like 2000 in animations files then I do see very slow fading animations but I want have animations in all four cases and faster fading.

I am using Kitkat 4.4.2. Thanks for your help

回答1:

This usually happened at Android 4.4.2. Try this

http://blog.csdn.net/xuewater/article/details/36398803



回答2:

As far as i remember, if you want to use the trasitions defined in themes you have to change activities using

startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());



回答3:

Unlike communities of PHP, Javascript or C#, Android community is very calm, no answers no solutions because of which only solution I have is to disable animations altogether:

<item name="android:windowAnimationStyle">@null</item>