【问题标题】:Android: Custom Animation lost after Orientation changeAndroid:方向更改后自定义动画丢失
【发布时间】:2015-07-14 16:54:56
【问题描述】:

我进行了大量研究,并尝试了所有我能想到的东西。

基本上,我有 3 个活动

活动 1 -> 活动 2 -> 活动 3

我已经设置了slide_left 和slide_right 动画文件。 基本上当用户点击进入活动 2 时 - 页面从右侧滑入。但是,当用户单击返回时(操作栏上的主页按钮)。它应该向相反的方向滑动。

当它到达 Activity 3 并且用户旋转设备时,幻灯片动画的方向是错误的。 =(这只发生在用户旋转设备时。

onCreate()

// Override animation so that it animates as a slide in from left
overridePendingTransition(R.anim.slide_left_in, R.anim.slide_left_out);

这就像当用户旋转设备时它失去了动画变化。

我发现了这个错误: https://code.google.com/p/android/issues/detail?id=25994

有谁知道解决方法吗?处理这个问题的最佳方法是什么??

【问题讨论】:

    标签: android android-animation android-orientation onconfigurationchanged


    【解决方案1】:

    我终于明白了!

    在 onCreate() 方法中:

    // Only run the animation if we are coming from the parent activity, not if 
    // we are recreated automatically by the window manager (e.g. device rotation)
    if (savedInstanceState == null) {
         // Override animation so that it animates as a slide in from left
         overridePendingTransition(R.anim.slide_left_in, R.anim.slide_left_out);
    }
    

    我已经对此进行了测试,并且效果很好。

    参考:https://www.youtube.com/watch?v=CPxkoe2MraA

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多