Android-based jitter Animation

Source: Internet
Author: User

Using an animation to make the control shake is actually to make the horizontal movement (which can be mixed with other types of rotation) of the animation loop playback, using the interpolator class.

The principle is very simple. I will not talk about it anymore,CodeAs follows:

Activity Code:

 
This. BTN. setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view v) {textview yearandmouth = (textview) jgworklogdateandoperapanel. this. findviewbyid (R. id. year_mounth_text); animation cycleanim = animationutils. loadanimation (context, R. anim. img_anim); yearandmouth. startanimation (cycleanim );}});

Imag_anim.xml

<? XML version = "1.0" encoding = "UTF-8"?> <Set xmlns: Android = "http://schemas.android.com/apk/res/android"> <translate Android: Duration = "100" Android: fromydelta = "0" Android: toydelta = "500" Android: fromxdelta = "0" Android: toxdelta = "1" Android: repeatcount = "5" Android: repeatmode = "restart" Android: interpolator = "@ anim/cylce"/> <rotate Android: Duration = "300" Android: effectx = "100% P" Android: effecty = "100% P" Android: fromdegrees = "90" Android: interpolator = "@ anim/cylce"/> </set>

Cylce. xml

<? XML version = "1.0" encoding = "UTF-8"?> <! -- Officially parses the animation cycle accelerator: -- accelerateinterpolator: the animation changes from the start to the end, which is a process of acceleration. -- Decelerateinterpolator: the animation starts from the beginning to the end, and the change rate is a deceleration process. -- Cycleinterpolator: the animation starts from the beginning to the end, and the change rate is the sine curve of the given number of cycles. -- Acceleratedecelerateinterpolator: the animation starts from the beginning to the end, and the change rate is the process of accelerating and slowing down. -- Linearinterpolator: the animation changes linearly from start to end. --> <Cycleinterpolator xmlns: Android = "http://schemas.android.com/apk/res/android" Android: cycles = "5"/>

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.