【问题标题】:Android Fragment Transaction with animation causes white flash带有动画的Android Fragment Transaction导致白闪
【发布时间】:2015-03-24 18:38:38
【问题描述】:

我有两个片段。片段 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();
}

【问题讨论】:

  • 您找到解决方案了吗?我现在遇到了类似的问题

标签: android android-fragments android-animation fragmenttransaction


【解决方案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-->

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-26
    • 2015-01-31
    • 2015-05-16
    • 2012-03-11
    • 2016-07-05
    • 1970-01-01
    相关资源
    最近更新 更多