I'm implementing Fragment transition animations.
My exit
animation is
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="together">
<objectAnimator
android:propertyName="scaleX"
android:valueType="floatType"
android:valueFrom="1.0"
android:valueTo="0.95"
android:duration="300"/>
<objectAnimator
android:propertyName="scaleY"
android:valueType="floatType"
android:valueFrom="1.0"
android:valueTo="0.95"
android:duration="300"/>
<objectAnimator
android:propertyName="x"
android:valueType="floatType"
android:valueFrom="0"
android:valueTo="10dp"
android:duration="300"/>
</set>
enter
animation is:
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="x"
android:valueType="floatType"
android:valueFrom="1280"
android:valueTo="0"
android:duration="400"/>
Transaction is created like this:
fragmentManager.beginTransaction()
.setCustomAnimations(enter, exit, popEnter, popExit)
.replace(CONTENT_CONTAINER_ID, newFragment)
.addToBackStack(null)
.commit();
At normal animation speed the unwanted effect is almost invisible due to short animation duration, but, when you slow them down you can clearly see, that z-order
is wrong.
Entering fragment animation is below exit fragment animation. Is there a workaround to remedy that?
At a high level, here's how to make a fragment transition with shared elements: Assign a unique transition name to each shared element view. Add shared element views and transition names to the FragmentTransaction . Set a shared element transition animation.
popEnterAnim. The custom enter Animation/Animator that should be run when this destination is popped from the back stack. final int. popExitAnim. The custom exit Animation/Animator that should be run when this destination is popped from the back stack.
Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.
This is probably already outdated, but I just faced the same problem. I solved it by defining two content areas in my XML, like:
<FrameLayout>
<FrameLayout id="@+id/oldFragment" />
<FrameLayout id="@+id/newFragment" />
</FrameLayout>
I would load the first fragment to oldFragment
and my transaction looks like this:
getActivity().getSupportFragmentManager()
.beginTransaction()
.remove(old_frag)
.add(R.id.newFragment, new_frag)
.addToBackStack(null)
.commit();
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With