Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slider animation between activities

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!

like image 688
Adriano Bellavita Avatar asked Apr 18 '26 12:04

Adriano Bellavita


1 Answers

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.

like image 67
Blo Avatar answered Apr 21 '26 02:04

Blo