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...
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();
<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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With