2

我做了大量的研究,并尝试了我能想到的一切。

基本上,我有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

有谁知道解决方法?处理这个的最好方法是什么?

4

1 回答 1

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

于 2015-07-14T21:33:19.120 回答