简体   繁体   中英

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.

Check this if you are looking for Top-Bottom and Bottom-Up animations :

Android Animation Example

You can change the value of fromDelta and toDelta if you want from left-right and right-left animations.

Hope this helps.

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 );

For bottom to Top animation use this:

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

you can specify the duration that you want to implement in mili seconds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM