19

I read the below link before posting this.

How to apply slide animation between two activities in Android?

I need to know how to make activity slideup xml animation. like what they have done for fadein and fadeout.

Community
  • 1
  • 1
praveen kumar
  • 828
  • 4
  • 14
  • 22
  • Hi You can make use of fromYDelta and toYDelta in your animation layout... Providing values from -100 to 0 and 0 to 100 will gives the effect of slide up and slide down. And never forgor to override the default transition by calling the method `overridePendingTransition`. HTH, – iDroid Aug 11 '12 at 06:02
  • Not an answer to your question, but something which might be useful to you: when `onBackPressed` you could include a reverse animation (it's trickier for activities opposed to fragments). Check out [this example](https://stackoverflow.com/questions/39711666/activity-navigation-custom-animation-with-popenter-and-popexit-like-fragments) – P Kuijpers Jun 10 '17 at 13:20

4 Answers4

61

The accepted answer isn't what the question was asking, which is animations that slide up from the bottom and slide out from the top.

pull_up_from_bottom.xml:

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

push_out_to_bottom.xml:

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="@android:integer/config_longAnimTime"
    android:fromYDelta="0%"
    android:toYDelta="100%" />
akelec
  • 3,797
  • 3
  • 41
  • 39
georgiecasey
  • 21,793
  • 11
  • 65
  • 74
  • 1
    This really works fine but when 2nd activity start animation meanwhile first activity becomes invisible and 2nd activity slides over black area, which looks really weird. Can we change it like when 2nd activitie slides upto 0% then activity1 should become invisible. This effect same like in iOS presentViewController if you have idea about iOS. – Emy Sep 10 '15 at 14:40
  • 1
    @EmyStats You're probably looking for an approach like I've written down here: http://stackoverflow.com/questions/39711666/activity-change-animation-with-popenter-and-popexit-animations/41025993#41025993 (of course for YDelta instead of XDelta) – P Kuijpers Dec 07 '16 at 19:57
  • 1
    @EmyStats I found the solution just adding true in res/values/styles.xml within the – ivoroto Jan 29 '19 at 09:22
35

for slide_in xml :

<translate 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:duration="250" 
      android:fromXDelta="-100%p" 
      android:toXDelta="0%p">
</translate>

for slide_out xml:

<translate
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:duration="200" 
      android:fromXDelta="0" 
      android:toXDelta="100%p">
</translate>

Java code :

Intent intent = new Intent(this, newActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);

put both xml files in res/anim folder.

Mehul Boghra
  • 202
  • 3
  • 11
Mansi
  • 1,939
  • 4
  • 22
  • 40
7

This is what I was after:

res/anim/slide_up.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="100%"
android:toYDelta="0%" />

res/anim/slide_down.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="0%"
android:toYDelta="0%" />

res/anim/slide_down_reverse.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="0%"
android:toYDelta="0%" />

res/anim/slide_up_reverse.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="0%"
android:toYDelta="100%" />

YourActivity.kt

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    setContentView(R.layout.your_layout)

    overridePendingTransition(R.anim.slide_up, R.anim.slide_down)
}

override fun finish() {
    super.finish()

    overridePendingTransition(R.anim.slide_down_reverse, R.anim.slide_up_reverse)
}
0

You can use below code for slide up activity transition animation.

startActivity(new Intent(MainActivity.this, DataSetActivity.class));
overridePendingTransition(R.anim.slide_out_bottom, R.anim.slide_in_bottom);

R.anim.slide_out_bottom

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate
        android:duration="250"
        android:fromXDelta="0%"
        android:fromYDelta="100%"
        android:toXDelta="0%"
        android:toYDelta="0%" />
</set>

R.anim.slide_in_bottom

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate
        android:duration="200"
        android:fromXDelta="0%"
        android:fromYDelta="0%"
        android:toXDelta="0%"
        android:toYDelta="100%" />
</set>
Maddy
  • 4,525
  • 4
  • 33
  • 53
Mehul Boghra
  • 202
  • 3
  • 11