How do I make an image shake/wiggle when clicked?

student2015 picture student2015 · May 4, 2012 · Viewed 19.6k times · Source

I have an imagebutton that I would like to make shake/wiggle when it is touched. I would like it to wiggle in a manner similar to iPhone app icons do when they are pressed for a very long time.

Thanks!

Answer

Simon picture Simon · Mar 27, 2014

try to use this one:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate
        android:duration="70"
        android:fromDegrees="-5"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="5"
        android:repeatMode="reverse"
        android:interpolator="@android:anim/linear_interpolator"
        android:toDegrees="5" />
    <translate
        android:fromXDelta="-10"
        android:toXDelta="10"
        android:repeatCount="5"
        android:repeatMode="reverse"
        android:interpolator="@android:anim/linear_interpolator"
        android:duration="70" />
</set>