Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Fragment transition exit animation played above enter animation

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?

like image 980
Martynas Jurkus Avatar asked Feb 26 '14 13:02

Martynas Jurkus


People also ask

How to animate Fragment transition in android?

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.

What is popEnterAnim?

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.

What is transition animation in Android?

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.


1 Answers

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.

like image 59
Flo Avatar answered Jan 03 '23 20:01

Flo