Slider animation between activities

12,817

I had a similar problem then I found, (as the z-order in css) there is a really great parameter for the animations: android:zAdjustment: "allows for an adjustment of the Z ordering of the content being animated for the duration of the animation". You will able to display the next activity behind the previous activity. You have 3 possible values:

  • normal: default value equals to 0
  • bottom: displayed in -1; value to be behind
  • top: value for 1; displayed at the top

Therefore, the slide_to_top.xml:

<translate 
    android:zAdjustment="top"
    android:fromYDelta="0"
    android:toYDelta="100%p"
    android:duration="2000" />  

Also you don't need to set a no_anim animation because your next activity will have the default value 0 and your previous activity will have +1. Just tested and it works like a charm, really! Then, the method:

overridePendingTransition(0,R.anim.slide_to_top);  

I really hope you found a way to resolve this. However, this solution might help someone which wants the same behaviour than yours.

Share:
12,817

Related videos on Youtube

Adriano Bellavita
Author by

Adriano Bellavita

Updated on September 14, 2022

Comments

  • Adriano Bellavita
    Adriano Bellavita almost 2 years

    I have to implement a simple animation between 2 activities: I've already implemented some simple animations, but last one is a little bit more difficult to realize.

    The animation should act like this: Activity A (on screen) slides from YDelta = 0 to Ydelta = -100%. In the meantime, Activity B is already in its final position (it doesn't move, no translation needed...) and it's slowly showed.... Like a courtain...

    I'tried in this bad way:

    overridePendingTransition(R.anim.no_anim, R.anim.slide_to_top);
    

    no_anim:

    <translate android:fromYDelta="0" android:toYDelta="0" android:duration="2000"/> 
    

    slide_to_top:

     <translate android:fromYDelta="0" android:toYDelta="100%p" android:duration="2000"/> 
    

    The result is not correct: Activity B (that is binded to no_anim) is immediatly showed on the screen, and so Activity A simply disappear...

    How can I solve my problem?

    TY and BR!

  • Adriano Bellavita
    Adriano Bellavita almost 11 years
    Thanks for the quick response: but in your example, both activities move from a direction to another. In my case, only the exit activity has a real animation (it moves from Ydelta = 0 to YDelta = -100p), while activity B doesn't move! It's already in its final position and it's slowly showed. I don't want it to appear from the bottom of the screen. Like a courtain!
  • An-droid
    An-droid almost 11 years
    You can use ydelta instead of xdelta, and in the method overridependingtransition you only provide the transitions for the only view you want to animate ?