Home » Android » android – Activity sliding from bottom to top but background activity should not moved

android – Activity sliding from bottom to top but background activity should not moved

Posted by: admin April 23, 2020 Leave a comment

Questions:

I am trying to slide an Activity from Bottom to Top which I am able to do.

But while sliding from bottom to top my background activity is also sliding to bottom.
I want to keep background activity to same position as it was, so that the new activity will seem as a overlay to background activity when open.

Here are my slide_in_up.xml

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

and slide_out_up.xml

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

How can I do that?
Thanks…

How to&Answers:

Then provide an outgoing animation to make the current Activity stay still:

overridePendingTransition(R.anim.slide_in_up, R.anim.stay);

stay.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%p"
    android:toYDelta="0%p" />

Answer:

slide_up.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator">

    <translate
        android:duration="@android:integer/config_longAnimTime"
        android:fromYDelta="100%p"
        android:toYDelta="0" />

</set>

slide_down.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator">

    <translate
        android:duration="@android:integer/config_longAnimTime"
        android:fromYDelta="0"
        android:toYDelta="100%p" />

</set>

stay.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%p"
    android:toYDelta="0%p" />

Open Activity

startActivity(new Intent(FromActivity.this, ToActivity.class));
overridePendingTransition(R.anim.slide_up, R.anim.stay);

Close Activity

finish();
overridePendingTransition(R.anim.stay, R.anim.slide_down);

Answer:

You can simply call overridePendingTransition(R.anim.slide_in_up, 0)

0 means no animation.