Android 为什么片段退出动画不起作用?

Android 为什么片段退出动画不起作用?,android,android-fragments,kotlin,Android,Android Fragments,Kotlin,我添加了从下到上的动画片段,当按下back或调用popBackStack时,它应该从上到下 val confirmFragment = ConfirmFragment.Companion.newInstance(item) val transaction = MainActivity.getMainActivity(context)!!.supportFragmentManager.beginTransaction() transaction.addToBackStack(tag) transa

我添加了从下到上的动画片段,当按下back或调用popBackStack时,它应该从上到下

val confirmFragment = ConfirmFragment.Companion.newInstance(item)
val transaction = MainActivity.getMainActivity(context)!!.supportFragmentManager.beginTransaction()
transaction.addToBackStack(tag)
transaction.setCustomAnimations(R.anim.slide_in_bottom, R.anim.slide_out_top)
transaction.replace(R.id.over_view, confirmFragment, tag)
transaction.commit()
现有xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="700"
        android:fromYDelta="100%"
        android:toYDelta="0%" >
    </translate>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="1700"
        android:fromYDelta="0%"
        android:toYDelta="100%" >
    </translate>
</set>
EnterAnimation xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="700"
        android:fromYDelta="100%"
        android:toYDelta="0%" >
    </translate>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="1700"
        android:fromYDelta="0%"
        android:toYDelta="100%" >
    </translate>
</set>
enter动画可以工作,但是当片段存在时它就不工作了。请删除xml代码中的set标记

换成这个

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="700"
    android:fromYDelta="100%p"
    android:toYDelta="0%p">
</translate>


您需要:改为设置自定义动画int-enter、int-exit、int-popEnter、int-popExit。@马克:谢谢,请写下您的评论作为答案,我可以接受。