36

windowAnimationStyle的动画无效

 3 years ago
source link: https://blog.csdn.net/ljphhj/article/details/120231211
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

windowAnimationStyle的动画无效

胖虎 2021-09-10 23:17:26 5

晚上发现配置的windowAnimationStyle中的动效一直无效。【表现:A -> B,B有进入动画,而A没有退出动画(android:activityOpenExitAnimation不生效)】
【修改xml的时候,需要卸载一下app,试了下很多次,不卸载重装,可能不生效,会导致认为自己修改无效】

<style name="AppThemeSlideAnimation" parent="@android:style/Animation.Activity">
        <item name="android:activityOpenEnterAnimation">@anim/slide_right_in</item>
        <item name="android:activityOpenExitAnimation">@anim/slide_left_out</item>
        <item name="android:activityCloseEnterAnimation">@anim/slide_left_in</item>
        <item name="android:activityCloseExitAnimation">@anim/slide_right_out</item>
    </style>
<style name="Theme.MyApplicationD" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@android:color/white</item>

        <item name="android:windowIsTranslucent">true</item>
        
        <!-- 切换动画 -->
        <item name="android:windowActivityTransitions">true</item>
        <item name="android:windowAnimationStyle">@style/AppThemeSlideAnimation</item>

    </style>

后面发现原来是
true
导致

windowIsTranslucent 为生命周期带来的影响

其实这个属性带来的不良影响还有不少,最典型的就是 Activity 生命周期影响
根据 windowIsTranslucent 有 true/false 两种状态那两个 Activity 就有四种情况:

A:true,B:false A:onPause->onStop
A:true,B:true A:onPause
A:false,B:false A:onPause->onStop
A:false,B:true A:onPause

导致Activity 转场动画失效
这个问题是个很棘手的问题,我分别在 preL(4.4) 和 aboveL(8.0) 上做了很多的测试,发现如果你的 Application 中指定的 Theme 是 translucent 的并且没有为 Activity 指定特定的 Theme,也就是说你的所有 Activity 都是透明的,这样就带来一个问题,那就是通过以下方法指定的转场动画全部失效:

其转场行为会变成入场动画仍旧是系统默认,而出场则无效。但是存在这样一种状况,我们为栈底 Activity 设置一个特定的 Theme,它的 windowIsTranslucent 属性为 false,也就是说栈底 Activity 是不透明的,换句话说,对于 Launcher 来说,新 Task 的栈底 Activity 不是 translucent 的,不会影响 Luancher 的行为。

所以,解决方案就是将这个属性字段去掉。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK