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

时间:2015-03-24 18:38:38

标签: android android-fragments android-animation 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();
}

1 个答案:

答案 0 :(得分: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-->
相关问题