带有动画的Android Fragment Transaction会导致白色闪烁

Nat*_*th5 8 android android-animation android-fragments fragmenttransaction

我有两个片段.片段A最初在视图中.当用户按下按钮时,使用以下方法将片段B动画化为视图.当我弹出片段B时,它会在视图中向下移动,但在完成后屏幕会闪烁白色.不确定是什么导致这种情况,似乎只发生在kit-kat而不是棒棒糖上.正在使用的动画是向上滑动并向下滑动在xml中定义的动画.

@Override
public void loadFragment(BaseFragment fragment, boolean replace, boolean addToBackStack, int animIn, int animOut, int animPopIn, int animPopout) {
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    if (animIn != -1 && animOut != -1 && animPopIn != -1 && animPopout != -1) {
        transaction = transaction.setCustomAnimations(animIn, animOut, animPopIn, animOut);
    } else if (animIn != -1 && animOut != -1) {
        transaction = transaction.setCustomAnimations(animIn, animOut);
    }

    if (replace) {
        transaction = transaction.replace(R.id.container, fragment);
    } else {
        transaction = transaction.add(R.id.container, fragment);
    }

    if (addToBackStack) {
        transaction = transaction.addToBackStack(null);
    }

    transaction.commit();
}
Run Code Online (Sandbox Code Playgroud)

小智 1

对我来说,bottomBarNavigation、NavigationDrawer 的崩溃动画以及当我使用替换片段时

<FrameLayout
            android:id="@+id/container"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <!--android:animateLayoutChanges="true" //THIS LINE CRASH THE ANIMATIONS-->
Run Code Online (Sandbox Code Playgroud)