简体   繁体   中英

Fragment Transaction Animation not Working in Android 6.0+

I am using the setCustomAnimations() method to absolutely no effect in Android 6.0.1. All that happens is that the fragment gets stuck for the duration of the animation to the left of the screen leaving a white space on the rest of the screen and then occupies the screen without any animation. It works perfectly in all the versions <6.0. I'm using the method as follows:

FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations
            (R.anim.slide_in_left, R.anim.slide_out_left, 0, 0);
MyFragment myFragment = new MyFragment();
fragmentTransaction.replace(R.id.fragmentContainer, myFragment,
            ResourceUtil.resByName(context, R.string.myFragmentText));
fragmentTransaction.commit();

Also, the slide_in_left XML file is as follows:

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
    android:fromXDelta="-100%" android:toXDelta="0%"
    android:fromYDelta="0%" android:toYDelta="0%"
    android:duration="300"/>
</set>

Use this:

 fragmentTransaction.setCustomAnimations(R.anim.anim_appear, R.anim.s_down);

more here .

Still not working? Check your xml. The -100% may lead to an issue.

So change the animation to this:

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
    android:fromXDelta="0%" android:toXDelta="100%"
    android:fromYDelta="0%" android:toYDelta="0%"
    android:duration="300"/>
</set>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM