我有两个 fragment 。 fragment A 最初在 View 中。当用户按下按钮时,Fragment B 会使用下面的方法动画化到 View 中。当我弹出 fragment B 时,它会在 View 之外进行动画处理,但就在它完成时屏幕闪烁白色。不确定是什么原因造成的,似乎只发生在 kit-kat 上而不是 Lollipop 上。使用的动画是在 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 的崩溃动画以及当我使用替换 fragment 时
<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-->
关于带有动画的 Android Fragment Transaction 导致白色闪光,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29240385/