Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bounce button on tap

does anybody know is there any xml animation that enables button to bounce for a few seconds. If you can and have share some examples...

like image 516
Darko Petkovski Avatar asked Feb 21 '13 15:02

Darko Petkovski


2 Answers

Here is a simple way to do it using an ObjectAnimator. If you want this to work pre-honeycomb, you can either use the same syntax and do it with a view animation, or use NineOldAndroids.

ObjectAnimator animY = ObjectAnimator.ofFloat(button, "translationY", -100f, 0f);
animY.setDuration(1000);//1sec
animY.setInterpolator(new BounceInterpolator());
animY.setRepeatCount(numRepeats);
animY.start();
like image 118
Jameo Avatar answered Oct 22 '22 14:10

Jameo


    <set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:interpolator="@android:anim/bounce_interpolator">

    <scale
        android:duration="500"
        android:fromXScale="0.5"
        android:toXScale="1.0"
        android:fromYScale="0.5"
        android:toYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%" />
</set>

Above animation code put in anim folder and set it to any view using java code:

Animation animation = AnimationUtils.loadAnimation(this,R.anim.bounce);
textview.startAnimation(animation);
like image 33
Ramij Avatar answered Oct 22 '22 13:10

Ramij