android - fragment 在移除时闪烁

标签 android android-fragments animation

如果我在将 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/

相关文章:

java - 是否需要在fragment onActivityCreated 方法中检查父 Activity 是否为空?

android - 这些代码 fragment 有什么区别?

html - SVG 简单动画

iphone - 为什么这个动画选择器不会被调用?

android - 媒体播放器 : How to update progress every second?

android - 如何在 Android 上使用 .p12 证书?

android - 如何检查 wifi 是否可用(虽然 Wifi 已连接)

android - 如何检测 Nexus G1 的手机摄像头是否捕获了图像、视频

java - Android Fragment到Activity方法调用

html - 悬停效果看起来有问题(Microsoft Edge)