support-v4:27.1.0 fragment custom animations do not work as expected

柔情痞子 提交于 2019-12-04 03:08:57

I just hit the same problem. Support library 27.1.0 seems to have a problem with anim transitions that use the alpha property.

My impression is that the transition engine does not correctly implement a "fill-after", so that the fragment alpha quickly bounces back to 1 before the fragment is removed. This causes a blinking effect where the replaced fragment is briefly visible and then disappears.

I resolved the issue switching to animator transitions.

I.e. replaced my /res/anim/fade_in.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromAlpha="0"
    android:toAlpha="1"
    android:duration="500"
    />

with an analogous /res/animator/fade_in.xml

<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:propertyName="alpha"
    android:valueFrom="0"
    android:valueTo="1"
    android:duration="500"
    />

I did the same for the fade_out transition.

The blinking effect was fixed in the latest support library version 27.1.1. (see issue 74051124)

I have the exact same problem after upgrading the support library from 27.0.2 to 27.1.0. Instead of fading smoothly, the fragments blink several times.

It seems that all animators work as expected, except alpha animators.

However, I have found a workaround for this bug: If you disable the enter animation, the transition still fades. It does not fade in the exact same way as before, but it looks good (or even better) in my opinion.

The new enter animation (which I have named nothing.xml) is:

<?xml version="1.0" encoding="utf-8"?>
<set/>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!