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

我从底部到顶部添加带有动画的片段,然后当按下回调或调用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() 

ExitAnimation(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> 

EnterAnimation(xml)

 <?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> 

输入动画工作,但是当片段存在,它不起作用

删除你的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> 

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