android Lollipop 动画故障

标签 android android-layout android-fragments android-animation android-5.0-lollipop

在运行 Android 5 (Lollipop) 的设备中,默认布局动画有一个奇怪的行为。我正在使用一个包含多个 fragment 的 Activity ,这些 fragment 在运行时使用默认 fragment 管理器被替换。替换旧 fragment 时,我想使用动画来实现流畅的 UI 流程。在 Lollipop 之前的设备上,动画按预期工作,但在运行最新操作系统的设备上, fragment 之间的动画出现故障:

Glitch screen shot

我尝试使用默认的动画 xml 标签

android:animateLayoutChanges="true"

因为它不起作用,所以我使用这段代码更改了它但没有效果

mTransaction = mManager.beginTransaction();
        mTransaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
        mTransaction.remove(mFragment);
        mTransaction.add(R.id.container, mFragment, "fragment");
        mTransaction.commit();

我已经在不同的设备和 android 模拟器中测试了代码。奇怪的是,它在运行 pre-lollipop 运行最新操作系统 (5.0.1) 的 android 模拟器的设备上按预期工作。 但它不适用于运行 Android 5.0 的 Nexus 4 和 Nexus 5 等设备

有什么建议吗?有什么帮助吗?

提前致谢

编辑:

这似乎是一个错误,具体取决于所使用的设备。我已经在不同的设备(三星 Galaxy S4、HTC(一个 mini2、一个 M8、Desire S)、Nexus 4 和 5)上测试了代码,它只出现在谷歌 nexus 设备上。

编辑

解决动画问题的一种解决方法是通过

禁用硬件加速

<application android:hardwareAccelerated="false">

应用程序 list 中的标记。但是使用它会使应用程序非常慢。

解决方案

解决此问题的方法是为 Activity 设置背景图像/颜色/可绘制对象。 see

最佳答案

设置根 Activity 的背景颜色(当用户不可见时也是如此!)图形故障消失了。

关于android Lollipop 动画故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27897850/

相关文章:

android - 将度/分/秒转换为有效的 EXIF 接口(interface)字符串

android - 我有适配器问题。任何人都可以知道解决方案

android - 删除android studio布局预览中的水平和垂直虚线

android - 在 ListView 中添加项目

android - 如何在 Android 中制作 Top Dialog 或 sheet?

java - 无法在 Wowza GoCoder 的 PlayerActivity 中播放视频

android - 如何在android中的单例类中制作进度条

java - Android Market 错误 -17 和缺少但可用的相机 : Has anyone else encountered this and what can be done?

android - 如何在 NavHostFragment 中检索当前 fragment ?

android - 关闭 DialogFragment(不是 Dialog)onTouchOutside