Animation XML fragment with setTransition does not work

1

I've been programming with Android Studio for a long time, I do not like to use a lot of XML, so Animations usually create them in java but what I realized is that with the FragmentManager there is not a method to place it, it touches by XML with the setTransition like this:

MainActivity.java

FragmentManager FM=getSupportFragmentManager();
FM.beginTransaction().setTransition(R.anim.fadein).replace(R.id.root,new BlankFragment()).commit();

fadein.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="5000" />
</set>

Could you please tell me that I am wrong; checking in detail the LogCat does not launch anything

    
asked by junior 28.08.2018 в 17:30
source

1 answer

1

Hello according to the documentation the setTransaction method is to signify a standard effect to the fragment, if you want to assign your own animation you should use setCustomAnimations

You should do it in the following way:

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    transaction.setCustomAnimations(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
    transaction.replace(R.id.content_frame, newFragment);
    transaction.disallowAddToBackStack();

    transaction.commit();

In that example I use ones that are already the system, you can also add an animation by default in the FrameLayout in the following way:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/content_frame"
    android:layout_above="@+id/navigation"
    android:animateLayoutChanges="true">
</FrameLayout>

This if you handle your fragments in that way.

If you want to use a default animation then you use the setTransaction method

Example

transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    
answered by 29.08.2018 / 17:34
source