问题
I have the following style on in my style.xml
and is a follow up to my question here Activity transition effects: slide in for the top activity and scale for the bottom activity:
<style name="RevealTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@style/ActivityAnimation</item>
</style>
<style name="ActivityAnimation" parent="@android:style/Animation">
<item name="android:activityOpenEnterAnimation">@anim/animation_in</item>
<item name="android:activityOpenExitAnimation">@anim/animation_out</item>
<item name="android:activityCloseEnterAnimation">@anim/animation_back_in</item>
<item name="android:activityCloseExitAnimation">@anim/animation_back_out</item>
</style>
I have found that the style android:windowBackground
conflicts with android:windowAnimationStyle
and the animation is not fully displaying. If I include the above style as is in my style.xml and run my app, I get the following:
If I comment out the lines here:
<style name="RevealTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@android:color/transparent</item>
<!--<item name="android:windowIsTranslucent">true</item> COMMENTED OUT-->
<item name="android:windowAnimationStyle">@style/ActivityAnimation</item>
</style>
<style name="ActivityAnimation" parent="@android:style/Animation">
<item name="android:activityOpenEnterAnimation">@anim/animation_in</item>
<item name="android:activityOpenExitAnimation">@anim/animation_out</item>
<item name="android:activityCloseEnterAnimation">@anim/animation_back_in</item>
<item name="android:activityCloseExitAnimation">@anim/animation_back_out</item>
</style>
I don't understand why this is the case. I need the windowIsTranslucent for some of my other animations.
These are the xml animation class I'm using (thanks to Nikolai Doronin):
activity_in.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%p"
android:toXDelta="0%p"
android:duration="@integer/activityAnimationTime">
</translate>
</set>
activity_out.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="1.0"
android:toXScale="0.84"
android:fromYScale="1.0"
android:toYScale="0.84"
android:duration="@integer/activityAnimationTime"/>
<translate
android:fromYDelta="0%"
android:fromXDelta="0%"
android:toYDelta="8%"
android:toXDelta="16%"
android:duration="@integer/activityAnimationTime"/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.25"
android:duration="@integer/activityAnimationTime"/>
</set>
activity_back_in.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="0.84"
android:toXScale="1.0"
android:fromYScale="0.84"
android:toYScale="1.0"
android:duration="@integer/activityAnimationTime"/>
<translate
android:fromYDelta="8%"
android:fromXDelta="16%"
android:toYDelta="0%"
android:toXDelta="0%"
android:duration="@integer/activityAnimationTime"/>
<alpha
android:fromAlpha="0.25"
android:toAlpha="1.0"
android:duration="@integer/activityAnimationTime"/>
</set>
activity_back_out.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0%p"
android:toXDelta="100%p"
android:duration="@integer/activityAnimationTime">
</translate>
</set>
回答1:
You can try this, change
<style name="ActivityAnimation" parent="@android:style/Animation">
to
<style name="ActivityAnimation" parent="@android:style/Animation.Translucent">
来源:https://stackoverflow.com/questions/36207321/setting-style-androidwindowistranslucent-seems-to-conflict-with-windowanimation