2

How can I make slide up animation? I got this code thanks to user Romain Piel in this topic. But I can't figure how to make reverse effect. That Animation is for slide down but I want slide up. How can I do that? I am sorry if this is a bad question but animations are always confusing me. I have tried with other codes too but it doesn't look nice.

overridePendingTransition(R.anim.push_down_in,R.anim.push_down_out);

R.anim.push_down_in:

<?xml version="1.0" encoding="utf-8"?>  
<set xmlns:android="http://schemas.android.com/apk/res/android">  
  <translate android:fromYDelta="-100%p" android:toYDelta="0" android:duration="900"/>
</set>  

R.anim.push_down_out:

<?xml version="1.0" encoding="utf-8"?>  
<set xmlns:android="http://schemas.android.com/apk/res/android">  
  <translate android:fromYDelta="0" android:toYDelta="100%p" android:duration="900"/>
</set>  
Community
  • 1
  • 1
Slim C.
  • 1,119
  • 4
  • 25
  • 49

1 Answers1

5

You just need to adjust the from/to values. Look at it this way:

  1. You still want the movements to end/start at y = 0 respectively.
  2. You need to have then move in the opposite direction.

Therefore, it's just a matter of interchanging 100% and -100%. Easy.

R.anim.push_up_in

<?xml version="1.0" encoding="utf-8"?>  
<set xmlns:android="http://schemas.android.com/apk/res/android">  
  <translate android:fromYDelta="100%p" android:toYDelta="0" android:duration="900"/>
</set>  

R.anim.push_up_out

<?xml version="1.0" encoding="utf-8"?>  
<set xmlns:android="http://schemas.android.com/apk/res/android">  
  <translate android:fromYDelta="0" android:toYDelta="-100%p" android:duration="900"/>
</set>  
matiash
  • 54,791
  • 16
  • 125
  • 154
  • Yeah I figured it later, I was replacing wrong values. Anyway thanks. – Slim C. Jul 04 '14 at 07:48
  • what does 100%p signifies here? – alchemist Jul 03 '15 at 03:30
  • 1
    @alchemist "values from -100 to 100 ending with "%", indicating a percentage relative to itself; values from -100 to 100 ending in "%p", indicating a percentage relative to its parent; a float value with no suffix, indicating an absolute value" -- see http://developer.android.com/guide/topics/resources/animation-resource.html#Tween – matiash Jul 03 '15 at 15:10
  • Could you give the code for slide down animation also. Thanks. – khateeb Sep 15 '17 at 13:27