简体   繁体   English

片段交易动画无法在Android 6.0+中运行

[英]Fragment Transaction Animation not Working in Android 6.0+

I am using the setCustomAnimations() method to absolutely no effect in Android 6.0.1. 我正在使用setCustomAnimations()方法在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. 它在所有<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: 另外,slide_in_left XML文件如下:

<?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. 检查您的xml。 The -100% may lead to an issue. -100%可能会导致问题。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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