Abid Khan Abid Khan - 14 days ago 5
Android Question

Android: Activity Animation to top

I have written an xml that works well to move an activity from right to left on click. But now what exactly I want is to convert that xml in code that will move an activity from bottom to top on click.

Here is my xml for right to left

right1.xml

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

<translate
android:fromXDelta="-100%p"
android:toXDelta="0%p"
android:duration="200" />
</set>


And here is another xml right2.xml

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

<translate
android:fromXDelta="0%p"
android:toXDelta="100%p"
android:duration="200" />
</set>


And here I used this code for switching between activities

Intent intent = new Intent(Activity1.this, Activity2.class);

startActivity(intent);
Activity1.this.overridePendingTransition(R.anim.right1, R.anim.right2);


Now I want it to change to bottom top move, that is to move activity from bottom to top. Any help will be highly appreciated. Thanks in advance.

Answer

push_up_in.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"/>

push_up_out.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"/>

For changing activity :

Intent nextActivity = new Intent(getApplicationContext(),
                nextactivity.class);
startActivity(nextActivity);
overridePendingTransition( R.anim.slide_up_in, R.anim.slide_up_out );
Comments