我的style.xml
中有以下格式,并在此处跟进我的问题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>
我发现样式android:windowBackground
与android:windowAnimationStyle
冲突,动画未完全显示。如果我在style.xml中包含上述样式并运行我的应用程序,我会得到以下内容:
如果我在这里注释掉这些行:
<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>
我不明白为什么会这样。对于我的一些其他动画,我需要windowIsTranslucent。
这些是我使用的xml动画类(感谢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>
答案 0 :(得分:1)
你可以尝试这个,改变
<style name="ActivityAnimation" parent="@android:style/Animation">
到
<style name="ActivityAnimation" parent="@android:style/Animation.Translucent">