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!
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>
Try this for shaking the image on imageview click listener.
public void onClick(View v)
{
Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
findViewById(R.id.pw).startAnimation(shake);
}
See this snippet is taking from the android API Demo here
I like this one
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="-20"
android:toXDelta="19"
android:duration="20" />
<translate
android:startOffset="20"
android:fromXDelta="19"
android:toXDelta="-18"
android:duration="20" />
<translate
android:startOffset="40"
android:fromXDelta="-18"
android:toXDelta="17"
android:duration="20" />
<translate
android:startOffset="60"
android:fromXDelta="17"
android:toXDelta="-16"
android:duration="20" />
<translate
android:startOffset="80"
android:fromXDelta="-16"
android:toXDelta="14"
android:duration="20" />
<translate
android:startOffset="100"
android:fromXDelta="14"
android:toXDelta="-12"
android:duration="20" />
<translate
android:startOffset="120"
android:fromXDelta="-12"
android:toXDelta="10"
android:duration="20" />
<translate
android:startOffset="140"
android:fromXDelta="10"
android:toXDelta="-7"
android:duration="20" />
<translate
android:startOffset="160"
android:fromXDelta="-7"
android:toXDelta="4"
android:duration="20" />
<translate
android:startOffset="200"
android:fromXDelta="4"
android:toXDelta="0"
android:duration="20" />
<translate
android:startOffset="220"
android:fromXDelta="0"
android:toXDelta="0"
android:duration="20" />
</set>
Upper one is incorrect try this one.
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="100"
android:fromDegrees="-5"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:toDegrees="5" />
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