Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make bounce animation

I would like to do bounce animation of layer.

I have done that layer comes from right to center, now I would like to move it a little back and then back to center. That would create bounce effect.

I was thinking that I can do it with a translate like this:

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

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

<translate
    android:duration="900"
    android:fromXDelta="70%p"
    android:toXDelta="0%p" />

Well this code does not working, only thing I can achieve is that Layer comes from left to center, and then animation stops.

I cannot use this code: because it does not achieve what I want

setInterpolator(AnimationUtils.loadInterpolator(this,
                        android.R.anim.bounce_interpolator));

Any help would be appreciated.

like image 689
5er Avatar asked May 29 '14 16:05

5er


1 Answers

You can use the BounceInterpolator to have this effect. The docs contain a very good description how to use it in XML. Just have a animation xml like this:

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

    android:interpolator="@android:anim/bounce_interpolator">

    <!-- Use your working translate animation here-->
    <translate
        android:duration="900"
        android:fromXDelta="100%p"
        android:toXDelta="0%p" />
</set>
like image 105
Steve Benett Avatar answered Oct 08 '22 20:10

Steve Benett