support-v4:27.1.0片段自定义动画无法正常工作 [英] support-v4:27.1.0 fragment custom animations do not work as expected

查看:73
本文介绍了support-v4:27.1.0片段自定义动画无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

片段动画在 support-v4:27.1.0

getSupportFragmentManager()
       .beginTransaction()
       .setCustomAnimations(ENTER_ANIM , LEAVE_ANIM)
       .replace(R.id.main_activity_fragment_place_holder, fragment)
       .addToBackStack(tag)
       .commitAllowingStateLoss();

输入动画

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

离开动画

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

推荐答案

我只是遇到了同样的问题.支持库27.1.0似乎对使用alpha属性的 anim 过渡有问题.

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

我的印象是过渡引擎未正确实现填充后",因此片段alpha在被删除之前迅速弹回了1.这会导致闪烁效果,其中被替换的片段短暂可见,然后消失.

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.

即替换了我的/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"
    />

与类似的/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"
    />

我对 fade_out 过渡做了同样的事情.

I did the same for the fade_out transition.

这篇关于support-v4:27.1.0片段自定义动画无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆