我有两个片段.片段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(); }
解决方法
对我来说,这个崩溃动画的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-->