android - 支持 Fragment 弹出动画不工作

标签 android android-fragments android-animation

我在我的应用中使用 v4 支持 fragment 。我有一项 Activity ,用户可以通过单击按钮查看更多信息。信息屏幕应该从底部向上滑动,覆盖 Activity ,当按下背部时,向下滑动。这是我目前使用的代码

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                    ft.setCustomAnimations(
                             R.anim.fragment_bottom_enter, 
                             R.anim.fragment_bottom_exit,                                  
                             R.anim.fragment_bottom_exit, 
                             R.anim.fragment_bottom_exit
                    );                 
                    ft.replace(R.id.fragmentContainer, fragment, TAG);
                    ft.addToBackStack(null);
                    ft.commit();

fragment_bottom_enter.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="500"
        android:fillAfter="true"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:fromYDelta="100%p"
        android:toYDelta="0%p" />
</set>

fragment_bottom_exit.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="500"
        android:fillAfter="true"
        android:fromYDelta="0%p"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toYDelta="100%p" />
</set>

上面的内容适用于进入动画( fragment 按预期从底部滑动)。但从未播放过流行动画。我什至尝试使用 android 的内置淡入淡出动画,但无济于事。非常感谢任何解决此问题的帮助。

最佳答案

老问题,但如果有人像我一样仍然遇到这个问题,你需要在添加时使用 fragmentTransaction.add() 而不是 fragmentTransaction.replace()动画 fragment 。

关于android - 支持 Fragment 弹出动画不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31668950/

相关文章:

android - 可以在没有 android-support-v4.jar 库的情况下使用 ViewPager 和 PagerAdapter 吗?

android - 在 Android 或 REST 中从纬度/经度生成地址

java - 使用 viewPager 时无法恢复 Activity

java - 更改圆形显示动画的颜色

android - 使用 CursorLoader 的 SQLite 查询

android - 基于资源值(value)的 Activity 导向

android - notifydatasetchanged 内部 fragment 与 ListView

java - 如何移动操作栏中的标题选项卡指示器?

android - 如何在安卓中播放 GIF

android - 如何用动画改变 NumberPicker 的值?