In this example, the "Shake" animation is added to the password input box. After a wrong password is entered, the text box is left and right to prompt that the user password is incorrect.
The Code is as follows:
[Html]
Animation shake = AnimationUtils. loadAnimation (this, R. anim. shake );
FindViewById (R. id. pw). startAnimation (shake );
Animation shake = AnimationUtils. loadAnimation (this, R. anim. shake );
FindViewById (R. id. pw). startAnimation (shake );
The Shake effect is achieved by setting cycleInterpolator cyclic motion through the translate translation Animation.
Anim's shake. xml
[Html]
<Translate
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: fromXDelta = "0" android: toXDelta = "10 ″
Android: duration = "1000" android: interpolator = "@ anim/cycle_7"/>
<Translate
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: fromXDelta = "0" android: toXDelta = "10 ″
Android: duration = "1000" android: interpolator = "@ anim/cycle_7"/> the definition of anim/cycle_7 is as follows:
[Html] view plaincopyprint?
<CycleInterpolator
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: cycles = "7"/>
<CycleInterpolator
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: cycles = "7"/> text box swinging around 7 to produce a swing effect.
Author: mapdigit