如果我在将 fragment 的 View 设置为可见性 View.GONE/View.INVISIBLE 后移除 fragment , fragment 的移除会导致 View 在移除之前再次闪烁。我怎样才能避免这种情况
fragment.getView().setVisibility(View.INVISIBLE);
之后:
ft.remove(fragment);
ft.commitAllowingStateLoss();
我没有使用隐藏,因为我自己做动画,在 onAnimationEnd 时我确实提交了删除。
然后Fragment的View闪烁然后被移除。
最佳答案
我通过将高度设置为 0 和 INVISIBLE 而不是 View.GONE 来做到这一点:
fragment.getView().setVisibility(View.INVISIBLE);
ViewGroup.LayoutParams params = fragment.getView().getLayoutParams();
params.height = 0;
fragment.getView().setLayoutParams(params);
关于android - fragment 在移除时闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38461654/