我在我的应用中使用 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/