Adding shake effect in Android
By admin
To add a shake effect to a textbox when an error occurs, first add the following 2 XML files in your anim folder
1) Control how fast or slow the shake should be in this file.
2) Control how far the shake go from left to right.
<pre class="lang:java decode:true "><translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0%"
android:toXDelta="1%"
android:duration="500"
android:interpolator="@anim/cycle" />
Control how many times you want the shake animation to occur.
<pre class="lang:default decode:true "><cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:cycles="3" />
Now, use the below code snippet to add shake animation to textbox in your code.
Following code using shake to grab users attention to an error in the email address field.
<pre class="lang:default decode:true ">...
Animation shake = AnimationUtils.loadAnimation(context, R.anim.shake);
emailText.startAnimation(shake);
errorText.setText("\u2757Invalid email address.");
...