Simon Chius
Simon Chius

Reputation: 476

Activity animation does not working properly

Edited: When the activity opens next activity, In the push_down_in.xml and push_down_out.xml, only the last translate animation is being animated. the first translate tag is not being animated. I want to make the animation like two different half. The first half must be very fast and the other should be slow. Using default interpolator I am not getting the exact output what I want. If anyone has got the idea please help me. The code is

pushing_down_out.xml

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

    <set android:ordering="sequentially" >
        <set>
            <translate
                android:duration="1000"
                android:fromYDelta="0"
                android:toYDelta="65%" />
        </set>
        <set>
            <translate
                android:duration="1500"
                android:fromYDelta="65%"
                android:toYDelta="100%p" />
        </set>
    </set>

</set>

pushing_down_in.xml

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

    <set android:ordering="sequentially" >
        <set>
            <translate
                android:duration="500"
                android:fromYDelta="-100%p"
                android:toYDelta="-35%" />
        </set>
        <set>
            <translate
                android:duration="1000"
                android:fromYDelta="-65%p"
                android:toYDelta="0" />
        </set>
    </set>

</set>

in the main activity

Intent i=new Intent(getApplicationContext(),Activity2.class);
startActivity(i);
overridePendingTransition(R.anim.push_down_out,R.anim.push_down_in);

Thanks in advance

Upvotes: 0

Views: 1503

Answers (1)

reVerse
reVerse

Reputation: 35264

I'm not 100% sure but I think android:ordering will be ignored if you're using ViewAnimations. Since you're only trying to make an animation which slows down over time you can use an interpolator as well. See the following code:

pushing_down_out.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:ordering="sequentially"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator">
    <translate
        android:duration="2500"
        android:fromYDelta="0"
        android:toYDelta="100%" />
</set>

pushing_down_in.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:ordering="sequentially"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator">
    <translate
        android:duration="1500"
        android:fromYDelta="-100%p"
        android:toYDelta="0%" />
</set>

So I basically just merged your translate-animations into one and applied an interpolator. The interpolator takes care of "making" the animation fast at first and slowing it down gradually over time.

Following all available Interpolators:

@android:anim/accelerate_decelerate_interpolator
@android:anim/accelerate_interpolator
@android:anim/anticipate_interpolator
@android:anim/anticipate_overshoot_interpolator
@android:anim/bounce_interpolator
@android:anim/cycle_interpolator
@android:anim/decelerate_interpolator
@android:anim/linear_interpolator
@android:anim/overshoot_interpolator

You can read more about them in the Docs (click).

Edit - Customize Interpolator

It's also possible to customize the speed of the interpolator. Just create a new *.xml file in your res/anim folder and add the following lines:

<accelerateDecelerateInterpolator
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:factor="2" />

The interesting line is the android:factor.
It's also possible to create your own Interpolator with your own formula. You can read more about it here (click).

Upvotes: 1

Related Questions