Android ApiDemos example (98): Views-& gt; Animation-& gt; Sha

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.