Reputation: 2053
I'm adding fragment with animation from bottom to top and then it should go from top to down when back is pressed or when popBackStack() is called.
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>
The enter animation works but when the fragment exists it doesn't work
Upvotes: 0
Views: 1173
Reputation: 8237
Remove the set
tag in your xml code .
Change to this .
<?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>
And
<?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>
Upvotes: 1