0

I have 3 activities, A, B, C.

From A they navigate to B, so I want to slide A to the left, and B from the right. When they navigate back to A from B, I want to slide B out to the right and A in from the left.

So it feels like they are just scrolling across 3 panes side by side like this:

enter image description here

I'm trying to do this in styles:

<style name="MyAnimation.WindowFromRight" parent="@android:style/Animation.Dialog">
    <item name="android:windowEnterAnimation">@anim/slide_in_left</item>
    <item name="android:windowExitAnimation">@anim/slide_out_right</item>
</style>

<style name="MyAnimation.WindowFromLeft" parent="@android:style/Animation.Dialog">
    <item name="android:windowEnterAnimation">@anim/slide_in_right</item>
    <item name="android:windowExitAnimation">@anim/slide_out_left</item>
</style>

<style name="ThemeFromLeft" parent="AppBaseTheme">
    <item name="android:windowAnimationStyle">@style/MyAnimation.WindowFromLeft</item>
</style>

<style name="ThemeFromRight" parent="AppBaseTheme">
    <item name="android:windowAnimationStyle">@style/MyAnimation.WindowFromRight</item>
</style>

However, the rules for B are complex, so it doesn't fit any of the styles above. B slides out to the left when C is being brought in, and out to the right when A is being brought in. And vice-versa for when B is coming into view.

I have tried to overridePendingTransition to cope with the special cases but it seems to conflict and animations seem to be compounded, should that be the case?

So my question is, can this be achieved with styles?

weston
  • 54,145
  • 21
  • 145
  • 203

1 Answers1

1

If I understand this properly, I think you would be better off using a ViewPager, and convert your 3 activities into 3 fragments. However if you app needs these 3 activities for some reason you can probably achieve what you want by calling overridePendingTransition(int, int).

Note that the first int is the resource id of a predefined xml animation for the entering animation and the second one is for the exiting animation. In your case you would need to create a 4 anim files (two for entering and 2 for exiting) and use the appropriate ones in each activity. You can have a look at Android Left to Right slide animation

Community
  • 1
  • 1
k3v1n4ud3
  • 2,904
  • 1
  • 15
  • 19
  • Thanks, `ViewPager` is a good suggestion. Unfortunately two of these activities are from a 3rd party library. – weston Mar 03 '14 at 12:08
  • Then the best way to go is to call overridePendingTransition in the appropriate place. – k3v1n4ud3 Mar 04 '14 at 02:40